如果有超过9个参数,如何访问函数的参数?

fzk*_*zkl 16 bash shell arguments function

前9个参数从$ 1- $ 9引用,$ 10被解释为$ 1后跟0.我如何解释这个并访问大于10的函数的参数?

谢谢.

neu*_*uro 27

使用 :

#!/bin/bash
echo ${10}
Run Code Online (Sandbox Code Playgroud)

要测试$ 10的差异,foo.sh中的代码:

#!/bin/bash
echo $10
echo ${10}
Run Code Online (Sandbox Code Playgroud)

然后 :

$ ./foo.sh first 2 3 4 5 6 7 8 9 10
first0
10
Run Code Online (Sandbox Code Playgroud)

如果您有以下情况,情况也是如此:

foobar=42
foo=FOO
echo $foobar # echoes 42
echo ${foo}bar # echoes FOObar
Run Code Online (Sandbox Code Playgroud)

使用{}时要删除歧义...

MY2C