开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜