gpt4 book ai didi

bash - 为什么 shell 脚本在其他地方运行相同的代码时会出现语法错误?

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:34 26 4
gpt4 key购买 nike

<分区>

我有一个从工作脚本复制而来的简单 shell 脚本。如果我将它复制粘贴到终端,它会起作用:

if true
then
true
fi

但是,当我使用 bash myscript 运行脚本时,出现了各种语法错误,就好像缺少某些关键字一样。

  • myscript: line 4: syntax error near unexpected token `fi' ,就好像 then 不存在一样。
  • myscript: line 6: syntax error: unexpected end of file ,就好像 fi 不存在一样。
  • myscript:第 4 行:意外标记 `$'\r' 附近的语法错误 .. 什么?

为什么这会发生在这个特定的脚本中,而不是在我的命令行或我从中复制的脚本中?

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