Fish和Bash跨平台变量扩展

时间:2020-03-03 16:01:33

标签: bash fish

我的package org.company.myApp.module1.service; import org.springframework.boot.SpringBootConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.FilterType; @SpringBootApplication @ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = Module1ServiceConfiguration.class)) public class Module1ServiceTestConfiguration { } 中有此脚本,该脚本将env var作为参数:

package.json

鱼自然会引发错误"scripts": { "foo": "./bin/foo-script.sh ${BAR}", }

我认为如果我用fish: Variables cannot be bracketed. In fish, please use {$BAR}.来调用它会起作用:

bash -c

但事实并非如此,

多个人需要使用"foo": "bash -c ./bin/foo-script.sh ${BAR}" ,因此它需要在Fish和Bash中都可以使用。

1 个答案:

答案 0 :(得分:2)

只需使用$BAR

"scripts": {
   "foo": "./bin/foo-script.sh $BAR",
}

${BAR}形式没有引号功能,它纯粹是将变量名与周围的字符串分开(例如,诸如${HOME}foo-$HOMEfoo这样的变量将以“ HOMEfoo”的名称扩展“)。

请注意,通常,在“用户的外壳程序”中运行脚本不是一个好主意。运行shell脚本的系统应指定所需的shell,例如/ bin / sh或fish

您尝试使用bash -c无效的原因是因为您的报价已关闭。你给鱼命令

bash -c ./bin/foo-script.sh ${BAR}

这意味着fish会尝试进行扩展,因为它没有被引用,因此将其视为语法错误并拒绝了该命令。

如果引用以下参数,这可能会起作用:

bash -c './bin/foo-script.sh ${BAR}'

因为要捕鱼,${BAR}用单引号引起来,所以它不在乎它们。