Use "$@"
to represent all the arguments:
(使用"$@"
表示所有参数:)
for var in "$@"
do
echo "$var"
done
This will iterate over each argument and print it out on a separate line.
(这将迭代每个参数并在单独的行上打印出来。)
$@ behaves like $* except that when quoted the arguments are broken up properly if there are spaces in them: ($ @的行为类似于$ *,但是当引用时,如果参数中有空格,则它们会被正确分解:)
sh test.sh 1 2 '3 4'
1
2
3 4
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…