bash中的简单语法错误

时间:2016-06-22 07:32:54

标签: 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 

1 个答案:

答案 0 :(得分:1)

它对我有用。您只需要通过重定向stdin从文件中获取输入,如@anubhava所述,并检查所有行尾是否正确。如果您没有足够的经验来使用sed,则可以使用任何文本编辑器执行此操作。

如果仍然无效,请在最后一个命令后放置;;它将在那时停止执行当前命令,因此后续"脏" 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 ;
相关问题