Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 表示环境变量10_Shell - Fatal编程技术网

Shell 表示环境变量10

Shell 表示环境变量10,shell,Shell,我将参数从Java程序传递到shell脚本,并使用shell脚本中的环境变量来接收参数。我可以通过使用$9获得9号之前的参数。但是如果我得到第10个参数,我会得到一个错误。我使用${10}获取第10个参数的输入。我在某些地方出错了。我不确定${10}格式,尽管它看起来确实合理。但是,您可以使用shift内置函数重用$1。差不多吧 #!/bin/sh a=$1 shift b=$1 echo "$a:$b" 你可以这样运行它 noufal@sanitarium% ~/foo.sh Hello

我将参数从Java程序传递到shell脚本,并使用shell脚本中的环境变量来接收参数。我可以通过使用$9获得9号之前的参数。但是如果我得到第10个参数,我会得到一个错误。我使用${10}获取第10个参数的输入。我在某些地方出错了。

我不确定
${10}
格式,尽管它看起来确实合理。但是,您可以使用
shift
内置函数重用
$1
。差不多吧

#!/bin/sh

a=$1
shift
b=$1

echo "$a:$b"
你可以这样运行它

noufal@sanitarium% ~/foo.sh Hello Goodbye
Hello:Goodbye

谢谢您的回复。但我正在将大约15个参数传递给shell,因此$1可能代表我发送的第一个参数。是的,但订单是相关的,不是吗?因此,您可以放置一个获取值的块,然后在处理开始之前对所有15个值重复移位。如果有非平凡的参数传递,您应该使用
getopts
。您得到的确切错误消息是什么?