【发布时间】:2013-06-10 12:06:18
【问题描述】:
我正在尝试将字符串之后的所有其他内容分配给 $@,但也选择了橙色。我认为这种转变将作为其余 args 的一部分,但输出也选择了橙色。
$ cat try.sh
#!/usr/bin/bash
str1="$1"
str2="$2"; shift
echo "$str1"
echo "$str2"
for i in "$@"
do
echo "rest are $i"
done
./try.sh apple orange 3 4 5
apple
orange
rest are orange
rest are 3
rest are 4
rest are 5
【问题讨论】:
-
在 bash 会话中键入
help shift。
标签: bash shell unix loops scripting