bash中的简单语法错误



这是我第一次试图编写bash脚本,而我感到非常困惑。我复制了一个简单的脚本来解析CSV文件,然后我得到语法错误

test.bash: line 8: syntax error near unexpected token `done'
test.bash: line 8: `done '

我与在线语法检查器进行了核对,但确实什么都没有。有人可以告诉我我在做什么错吗?这是代码:

#!/bin/bash
input="/input/file.cvs"
# Set "|" as the field separator using $IFS 
# and read line by line using while read combo 
while IFS='|' read -r f1
do
  echo "$f1 "
done 

它对我有用。如@anubhava所说,您只需要通过重定向stdin来获取文件的输入,然后检查所有末端是正确的。如果您感觉不足以使用sed

,您可以使用任何文本编辑器进行此操作。

如果它仍然不起作用,请在最后一个命令之后放置;;当时它将停止执行当前命令,因此随后的" Dirty" EOL无关紧要。

#!/bin/bash
input="/input/file.cvs"
# Set "|" as the field separator using $IFS 
# and read line by line using while read combo 
while IFS='|' read -r f1
do
  echo "$f1 "
done < $input ;

最新更新