echo $1 $2 $3 ' -> echo $1 $2 $3'
args=("$@")
echo ${args[0]} ${args[1]} ${args[2]} ' -> args=("$@"); echo ${args[0]} ${args[1]} ${args[2]}'
echo $@ ' -> echo $@'
echo Number of arguments passed: $# ' -> echo Number of arguments passed: $#'
这是输出
但我得到了这个。
Jasons-MacBook-Pro:bash jasonkim$ bash arguments.sh
-> echo $1 $2 $3
-> args=("$@"); echo ${args[0]} ${args[1]} ${args[2]}
-> echo $@
Number of arguments passed: 0 -> echo Number of arguments passed: $#
答案 0 :(得分:3)
问题不在于你不能,而是没有。
bash arguments.sh Bash Scripting Tutorial
答案 1 :(得分:0)
#!/bin/bash
for var in "$@"
do
echo "$var"
done
$ ./scr.sh a b c
输出:
a
b
c
bash arguments.sh arg1 arg2 arg3
?