2

I want to monitor rows of a dynamic file and I use watch command for this. I have 2 files: test-status and iplist_test. I control something in iplist_test and I type this output to test-status. iplist_test file has 150 rows and I want to see a result like 14/150 or 25/150 etc. I use the following command for this:

watch -n .1 echo -e "$(cat test-status | wc -l)\/$(cat iplist_test | wc -l)"

The command does not work like a watch command, it is static. I refresh manually for live results. What's wrong with my command?

1 Answer 1

4

The output is static because $() is resolved by your shell before watch starts.

Quoting with '' should help. Single quotes prevent expansion, this way $() will be passed literally to watch, then parsed every time:

watch -n .1 'echo -e "$(cat test-status | wc -l)/$(cat iplist_test | wc -l)"'

Also you misuse cat. This should work without any unnecessary cat processes:

watch -n .1 'echo -e "$(<test-status wc -l)/$(<iplist_test wc -l)"'

If there are single-quotes already in the command you want to watch then see this: How can I single-quote or escape the whole command line in Bash conveniently?

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .