Skip to content

Instantly share code, notes, and snippets.

@itxve
Last active April 28, 2021 05:55
Show Gist options
  • Save itxve/49e6fc6fcdf274dd7bc31dcb9590dd81 to your computer and use it in GitHub Desktop.
Save itxve/49e6fc6fcdf274dd7bc31dcb9590dd81 to your computer and use it in GitHub Desktop.
A Simple and Practical Shell Functions
# 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