添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

在shell脚本中不期待令牌'done'。

0 人关注

我对编写shell脚本并不熟悉,但我想编写一个脚本,在执行命令前检查一个文件当前是否打开。我得到的错误如下

 ./Script.sh: line 9: syntax error near unexpected token `done'
./Script.sh: line 9: `done'

作为奖励,我不知道"|"运算符的作用,我找到了一些shell语法网站,但由于它是一个单一的字符,所以搜索它的用途很困难。

#!/bin/bash
inotifywait -m -r -e create "sunshine" | while read NEWFILE
        if [ lsof | grep NEWFILE ]; then
                echo "found something";
                aws s3 sync sunshine s3://turnaround-sunshine/
    
linux
shell
Blue
Blue
发布于 2018-06-22
1 个回答
John Kugelman
John Kugelman
发布于 2018-06-22
已采纳
0 人赞同

Your if / else is missing a fi at the end.

| 创建了一个 pipe 在两个命令之间,将第一个命令的输出作为第二个命令的输入。顺便说一下, if 语句中的第二个管道不应该有方括号;而 grep NEWFILE 应该是 grep "$NEWFILE"