gpt4 book ai didi

bash - bash 中的语法错误仅在 Ubuntu 中

转载 作者:行者123 更新时间:2023-12-04 19:16:44 25 4
gpt4 key购买 nike

declare -a identifications=(
'10760260000119 - 34234324' # ok
)

declare -a years=(
2010
2011
2012
2013
2014
)

for identification in "${identifications[@]}"
do
for year in "${years[@]}"
do
downloader --type=CNPJ --format=XLS --identification=${identification:0:14} --password=${identification:16:20} --competence=${year} --output="$identification - $year"
done
done

我使用 MacBook Pro Yosemite 10 创建了这个 bash 脚本,现在我尝试在 ubuntu 14 服务器 (AWS) 中使用并导致语法错误:
bash/2010.sh: 1: bash/2010.sh: Syntax error: "(" unexpected

也许我需要安装一些软件包?

谢谢。

最佳答案

根据您的系统,使用 sh 时运行的程序可以变化。你基本上是在说“使用默认的 shell,不管它是什么”,所以你应该只在你限制自己使用 POSIX 标准 shell 时使用它。

如果 sh表示 bash在您的系统上,然后它将以兼容模式运行,这可能会导致某些功能(例如数组)被禁用(我说“可以”,因为我不确定细节 - 这因平台而异已经看到)。

长话短说,如果你想使用 bash 功能,你应该像 bash bash_program.sh 一样运行它。反而。

另外,我认为将 shebang 行添加到文件顶部 #!/bin/bash 是一种很好的做法。 , 使其可执行并像 ./bash_program.sh 一样运行它.这清楚地说明了脚本顶部的意图。

关于bash - bash 中的语法错误仅在 Ubuntu 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34881110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com