Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试执行这样的脚本,使用间接接受脚本
sh <<EOT for str in `cat test` do echo $str done EOT
文件“test”有内容
a b c
它给出了以下错误。
sh: line 2: syntax error near unexpected token `b' sh: line 2: `b'
任何人都可以澄清吗?我的目标是像上面那样执行脚本,而不是创建一个 shell 脚本文件 script.sh 并执行它(效果很好)
您的外壳正在插入 HEREDOC。为防止这种情况,请引用分隔符:
sh << 'EOT'
为了澄清,你所拥有的相当于:
sh <<EOT for str in a b c do echo done EOT
这使得语法错误相当明显。