Created
February 28, 2017 04:59
-
-
Save DmitryBe/f85d86e1f2da32923b5b665eca0c4b5e to your computer and use it in GitHub Desktop.
bash snips
This file contains hidden or 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
# input args length | |
echo 'args length: ' $# | |
# access arg2 | |
echo 'arg[2]: ' ${2} | |
# slice (from 2) | |
echo 'slice[2-]: ' ${@:2} | |
# declare array | |
array1=(1 2 3 4 5) | |
# loop array | |
for arg in $@ | |
do | |
echo $arg | |
done | |
# array length | |
echo 'legth: ' ${#array1[*]} | |
# function declaration | |
function say_hello { | |
echo 'hello ' $1 | |
exit | |
} | |
say_hello 'Dmitry' | |
# if else | |
if [ $1 = "start" ]; then | |
echo 'start' | |
else | |
echo 'no start' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment