Skip to content

Instantly share code, notes, and snippets.

@hyunjun

hyunjun/array.sh Secret

Last active August 17, 2017 02:11
Show Gist options
  • Save hyunjun/ba33945e80a4f899cc169f97aa351820 to your computer and use it in GitHub Desktop.
Save hyunjun/ba33945e80a4f899cc169f97aa351820 to your computer and use it in GitHub Desktop.
bash multiple arguments & array
#!/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
#!/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