Created
May 12, 2017 09:24
-
-
Save achmadns/bc1b13193605a2dfcb42f2869d059f0d to your computer and use it in GitHub Desktop.
Print and Iterate Shell Script Parameters
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
#!/bin/bash | |
: ' | |
Example | |
$ ./print-param.sh 4 2 3 4 5 6 | |
4 2 3 4 5 6 | |
4 | |
2 | |
3 | |
4 | |
5 | |
6 | |
max val: 4 | |
0 | |
1 | |
2 | |
3 | |
' | |
echo "Script name: $0" | |
# print all parameter | |
echo "Parameters: $*" | |
# save the arguments | |
args=("$@") | |
# backup the elements | |
ELEMENTS=${#args[@]} | |
for (( i=0;i<$ELEMENTS;i++)); do | |
echo ${args[${i}]} | |
done | |
# get the first parameter | |
max=${args[0]} | |
printf "max val: $max\n" | |
# finite loop up to first param -1 | |
for (( i=0;i<$max;i++)); do | |
echo $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment