0

I use watch to monitor the progress of file conversions.

watch -n 2 "echo Converted: $(ls *.mp3 | wc -l) of $(ls *.wav | wc -l) files"

When using command substitutions using the $(command) syntax the values don't get updated each time watch reruns the command within the double quotes. How to do this properly? Since this is a simple script with all kinds of "progress" monitors I'd like to keep the watch command and avoid something like pv.

ilkkachu
  • 138,973
Moka
  • 155
  • 1
  • 9

1 Answers1

2

TL;DR: you need to use singlequotes there, like this:

watch -n 2 'echo Converted: $(ls *.mp3 | wc -l) of $(ls *.wav | wc -l) files'

Explanation

Doublequotes are telling Bash to do string interpolation before passing the command to watch, so Bash evaluates those subshells, interpolates the output, and passes the whole shebang to watch, which never evaluates them again because it doesn't know about them.

James S.
  • 183