在shell脚本中执行循环时从中读取文件的语法

在shell脚本中执行循环时从中读取文件的语法,shell,Shell,此shell脚本包含while循环: while IFS = \| read SourceDB db_name Mysql_table hdfsdir libpath do # jobs done < $/root/SqoopWrapper/InputFile exit 0 而IFS=\\\读取SourceDB\u name Mysql\u表hdfsdir libpath 做 #工作 完成

此shell脚本包含while循环:

while IFS = \| read SourceDB db_name Mysql_table hdfsdir libpath
do
    # jobs

done < $/root/SqoopWrapper/InputFile

exit 0
而IFS=\\\读取SourceDB\u name Mysql\u表hdfsdir libpath
做
#工作
完成<$/root/SqoopWrapper/InputFile
出口0
shell脚本包含我要循环的输入文件

在执行死刑时,我得到了

“意外标记“完成”附近出现语法错误”


去掉作业中的空格

while IFS=\| read SourceDB db_name Mysql_table hdfsdir libpath
您可以使用在将来捕获这些类型的错误

$shellcheck myscript
第1行:
而IFS=\\\读取SourceDB db\u name Mysql\u表hdfsdir libpath
^--SC2162:不使用-r读取将损坏反斜杠。
^--SC1068:在赋值中,不要在=周围加空格。

您的问题是什么?表达式中似乎缺少分号,while循环的语法如下:while true;做“某事”;doneMy的问题是如何读取InputFile.txt内容以处理进一步的脚本。我对我的脚本进行了如下修改:确保如果我的脚本在回显变量$input时是正确的,那么它不会回显InputFile的内容
input=/root/SqoopWrapper1/InputFile.txt IFS='|'while read SourceDB db_name Mysql_table hdfsdir libpath do#process done<$input exit 0
@babsaai分号仅在所有内容都在同一行时才需要。请通过在中测试脚本来清除所有简单错误。这将帮助您清除
=
周围的不正确空格。