0

I have a watch on

jq -r '.' $(ls -t | head -1)"

The goal is to apply "jq -r '.'" to the most recently modified file in directory. Unfortunately, the command used to know the last modified file is evaluated when watch is launched, but not at refresh. How should i write it, so that all of the command is reevaluated at each refresh ?

Thanks

0

If you pass the command in single quotes it will be expanded on each cycle of watch rather than when you run the watch command, for example:

watch echo $(date)

watch 'echo $(date)'

The first command will print the original date over and over, the second command will run the date on each cycle and print a different date.

This is because you are passing the literal string echo $(date) to the watch command, which runs it each cycle and echos the correct date. If you don't use quotes, the shell will expand the $(date) and replace it with the output of the date command and pass that to watch, so it will print the same output over and over.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.