Bash 脚本中意外标记“if”附近的语法错误
syntax error near unexpected token `if' in Bash Scripting
试图找到包含 jane
的文件列表中的所有行,然后测试结果是否作为真实文件存在,并将它们的名称附加到文档中。这是我的代码:
#!/bin/bash
> oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch;
if test -e ~/$x: then
echo $x >> oldFiles.txt
fi
有人可以解释为什么我会收到以下错误吗?
syntax error near unexpected token `if'
建议尝试以下方法
#!/bin/bash
> oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch;
if (test -e ~/$x); then
echo $x >> oldFiles.txt
fi
done
试图找到包含 jane
的文件列表中的所有行,然后测试结果是否作为真实文件存在,并将它们的名称附加到文档中。这是我的代码:
#!/bin/bash
> oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch;
if test -e ~/$x: then
echo $x >> oldFiles.txt
fi
有人可以解释为什么我会收到以下错误吗?
syntax error near unexpected token `if'
建议尝试以下方法
#!/bin/bash
> oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch;
if (test -e ~/$x); then
echo $x >> oldFiles.txt
fi
done