Skip to content

Instantly share code, notes, and snippets.

@DmitryBe
Created February 28, 2017 04:59
Show Gist options
  • Save DmitryBe/f85d86e1f2da32923b5b665eca0c4b5e to your computer and use it in GitHub Desktop.
Save DmitryBe/f85d86e1f2da32923b5b665eca0c4b5e to your computer and use it in GitHub Desktop.
bash snips
# 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