我有一个从工作脚本复制的简单shell脚本.如果我将其复制粘贴到终端,它可以工作:
if true
then
true
fi
Run Code Online (Sandbox Code Playgroud)
但是,当我运行脚本时bash myscript,我会收到各种语法错误,就好像缺少某些关键字一样.
myscript: line 4: syntax error near unexpected token `fi' 好像then不在那里.myscript: line 6: syntax error: unexpected end of file好像fi不在那里.myscript: line 4: syntax error near unexpected token `$'\r' .. 什么?为什么会在这个特定的脚本中发生这种情况,而不是在我的命令行或我复制的脚本中?