开发者

UNIX shell script while loop

开发者 https://www.devze.com 2023-04-08 14:22 出处:网络
I am trying to write a script to track the progress of file change. I have the following till now: #!/bin/sh

I am trying to write a script to track the progress of file change.

I have the following till now:

#!/bin/sh
old=‘ls -l /tmp/file‘
new=‘ls -l /tmp/file‘
while [ "$old" = "$new" ]
do
    new=‘ls -l /tmp/file‘
done
echo "The file has been changed"

The above program when run gives the message:

new: comma开发者_如何学Pythonnd not found

Can someone please help.

Thanks


You probably have space around =.

In shell, when you assign the values you cannot put space around =:

MY_VAR = "my value"  # this is wrong!

Shell will think: "call MY_VAR with arguments: ('=', 'my value') ", but wait! I don't know the command "MY_VAR"!

You need to do it this way:

MY_VAR="my value"  # this is OK!

BTW, consider using inotifywatch command. Here's example:

inotifywatch -v -e access -e modify -t 60 -r /file/to/watch
0

精彩评论

暂无评论...
验证码 换一张
取 消