Bash脚本:复制特殊变量$ @

时间:2019-01-25 11:14:19

标签: bash

我想复制提供给Bash脚本的所有参数(特殊变量$@),以便导出它们。我尝试了以下代码:

### my_script.sh

echo "Case 1:"
for var in "$@"
do
    echo "$var"
done

echo ""
echo "Case 2:"
export a="$@"
for var in $a
do
    echo "$var"
done

不幸的是,用my_script.sh "abc" "de f" "ghi" "j k"调用它会产生错误的输出:空格打破了参数列表。如何复制$@的参数?

Case 1:
abc
de f
ghi
j k

Case 2:
abc
de
f
ghi
j
k

0 个答案:

没有答案