Shell脚本:传递给数组时,带引号的引号引起来吗?

问题描述 投票:0回答:1

我有一个shell脚本,其中一部分是这样做的:

bundle exec rake parallel[${@:3}];

$ {@:3}是动态的,可能类似于-p thread11 THREAD = test_thread11,或者只是@ test.feature

rake任务期望一个参数,但是无论我怎样尝试,我都无法让shell脚本用引号将变量引起来,所以不要发送类似的内容

bundle exec rake parallel [“-p thread11 THREAD = test_thread11”]

我最终发送了

bundle exec rake parallel [-p thread11 THREAD = test_thread11]

这将导致rake任务失败。

使用echo语句,我可以通过执行以下操作获得正确的输出:>

echo“将使用运行命令”捆绑执行耙平行[['$ {@:3}'“]

将变量传递给任务时,变量的值是否可以用引号引起来?

我有一个shell脚本,其中一部分是这样做的:bundle exec rake parallel [$ {@:3}]; $ {@:3}是动态的,可能类似于-p thread11 THREAD = test_thread11,或者只是@ test.feature。rake ...

shell sh rake-task
1个回答
1
投票

[您似乎想使用"${*:3}"代替,它将从3个参数生成一个用空格分隔的单词,而不是由一系列单个单词组成的单词,每个参数一个。

© www.soinside.com 2019 - 2024. All rights reserved.