bash 脚本中出现语法错误 `("
syntax error `(" unexpected in bash script
我正在编写一个简单的 bash 脚本,我在 XX `(' unexpected
我的代码:
function myfun(){
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)
哪里出错了。我使用了 ShellCheck,没有检测到任何错误。
确保您是 运行 具有 bash
的脚本。该错误是常见的 dash
shell 错误。
我怀疑您脚本的第一行不是 #!/bin/bash
,即您可能完全遗漏了 shebang 行,导致使用默认的 shell(通常dash
尤其是在 /bin/sh -> dash
).
的 Debian 派生 Linux 上
尝试运行这个:
#!/bin/bash
myfun()
{
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)
我正在编写一个简单的 bash 脚本,我在 XX `(' unexpected 我的代码:
function myfun(){
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)
哪里出错了。我使用了 ShellCheck,没有检测到任何错误。
确保您是 运行 具有 bash
的脚本。该错误是常见的 dash
shell 错误。
我怀疑您脚本的第一行不是 #!/bin/bash
,即您可能完全遗漏了 shebang 行,导致使用默认的 shell(通常dash
尤其是在 /bin/sh -> dash
).
尝试运行这个:
#!/bin/bash
myfun()
{
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)