bash SCRIPT_PATH="${BASH_SOURCE[0]}" 替换错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15541876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:56:12  来源:igfitidea点击:

SCRIPT_PATH="${BASH_SOURCE[0]}" Bad substitution

bashvariables

提问by abkrim

On Centos my script work fine. But on Debian Squeeze when I run script, I got:

在 Centos 上,我的脚本运行良好。但是在 Debian Squeeze 上运行脚本时,我得到:

cpfailover.sh: 30: Bad substitution

Line of script say:

脚本行说:

SCRIPT_PATH="${BASH_SOURCE[0]}";

I have seen in many examples, even here, that is a correct line no. where is the problem.

我在很多例子中都看到过,即使在这里,这是一个正确的行号。问题出在哪儿。

回答by pynexj

Are you using /bin/sh? On Debian Squeeze, /bin/shis a symlink to /bin/dashwhich does not support ${array[0]}.

你在用/bin/sh吗?在 Debian Squeeze 上,/bin/sh是一个/bin/dash不支持${array[0]}.

回答by Even Cheng

Change your code to

将您的代码更改为

SCRIPT_PATH=
SCRIPT_PATH="${BASH_SOURCE[0]}";
;

instead of

代替

##代码##