2

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: command not found

Can someone please help.

Thanks

3
  • You'd probably want "$old" -eq "$new" Commented Sep 23, 2011 at 20:42
  • @Marc, no, in the shell = is string comparison and -eq is numeric comparison. Commented Sep 23, 2011 at 22:25
  • @Mike, You might want to throw a sleep 5 into your while loop. Commented Sep 23, 2011 at 22:26

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.