-
test
$ ./test.sh Argument 3 is 가 Argument 2 is a Argument 1 is 1
-
ref
-
-
Save hyunjun/ba33945e80a4f899cc169f97aa351820 to your computer and use it in GitHub Desktop.
bash multiple arguments & array
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/sh | |
CDIR=$(readlink -f $(dirname $(readlink -f ${BASH_SOURCE[0]}))) | |
[[ -f ${CDIR}/env.sh ]] && . ${CDIR}/env.sh || exit 1 | |
function error_handler() | |
{ | |
local status=${1:-1} | |
echo "ERROR at line (`caller 0`)" | |
exit ${status} | |
} | |
ARR=(one two three) | |
ARR_LENGTH=${#ARR[@]} | |
for (( i=0; i <${ARR_LENGTH}; i++ )); | |
do | |
ITEM="${ARR[$i]}" | |
echo $ITEM | |
done | |
for ITEM in "${ARR[@]}" | |
do | |
echo $ITEM | |
done |
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/sh | |
function multiple_args() | |
{ | |
args=("$@") | |
i=${#args[*]} | |
while [ "$i" -gt "0" ] ; do | |
echo "Argument $i is ${args[$((i-1))]}" | |
((i--)) | |
done | |
} | |
multiple_args 1 a 가 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment