Last active
April 28, 2021 05:55
-
-
Save itxve/49e6fc6fcdf274dd7bc31dcb9590dd81 to your computer and use it in GitHub Desktop.
A Simple and Practical Shell Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Simple and Practical Shell Functions | |
#!/usr/bin/env bash | |
prefix="====================================================================" | |
end="......................" | |
sucess="๐๐๐๐๐๐๐๐๐๐๐๐๐" | |
error="๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ๐ โ" | |
rocket="๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ ๐ " | |
# ๆฃๆตไธๆกๅฝไปคๆฏๅฆๆๅ | |
function hasSuccee() { | |
if [[ $? = 0 ]] | |
then | |
echo $prefix $1 successed $sucess | |
else | |
echo $prefix $1 has error $error | |
exit 1 | |
fi | |
} | |
# ๆถๅทฎๅจ ๅๆฐ1:้่ฆ่ฐ็จ็ๅฝๆฐๅ | |
# for Example | |
# countTime example | |
function countTime () { | |
start=`date +%s ` | |
$1 | |
end=`date +%s ` | |
echo ่ๆถ$(($end-$start))ๅต | |
} | |
# ็กฎ่ฎคๅฝๆฐ $1 ๅๆฐ1:ๆ็คบไฟกๆฏ๏ผๅๆฐ2: ็กฎ่ฎคๅ้่ฆ่ฐ็จ็ๅฝๆฐๅ | |
# for Example | |
# comfirm โ็กฎ่ฎคๅ ้คๅโ example | |
function comfirm () { | |
read -r -p "$1? [Y/n] " input | |
case $input in | |
[yY][eE][sS]|[yY]) | |
$2 | |
;; | |
[nN][oO]|[nN]) | |
echo "you Canceled $end" | |
exit 1 | |
;; | |
*) | |
echo "you Canceled $end" | |
exit 1 | |
;; | |
esac | |
} | |
# | |
function example () { | |
echo "I will called" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment