Shell script - I want to traverse through 2nd argument to last argument
How can I traverse through 2nd argument to last argument like:
for a开发者_如何转开发rg in $2-$@
do
echo $i
done
Please help
Actually, don't trust the arguments... they may contain spaces, or other special meta characters to the shell. Double quotes are your friends in shell scripts.
shift; #eat $1 for arg in "$@" do echo "$arg" done
When put in double quotes the "$@" takes on special magic to assure words are retained. Much better then $*. "$*" would process all arguments at once.
Double quotes are not a perfect solution, just the best easy one.
Use shift
in bash
.
shift
for arg in $@
do
echo $arg
done
args=("$@")
for arg in $(seq 2 `expr $# - 1`)
do
echo ${args[$arg]}
done
精彩评论