繁体   English   中英

Bash 脚本中意外标记“if”附近的语法错误

[英]syntax error near unexpected token `if' in Bash Scripting

尝试查找包含jane的文件列表中的所有行,然后测试结果是否作为真实文件存在,并将 append 的名称写入 Document。 这是我的代码:

#!/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

旧文件.txt

janeSearch=$(grep“简”../data/list.txt|剪切-d''-f 1,3)

对于 $janeSearch 中的 x; if (test -e ~/$x); 然后 echo $x >> oldFiles.txt fi 完成

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM