4

I want to run watch on a command which uses an optional command line argument, like this:

function queue() {
    watch -n 10 'squeue -p ${1:-default} -o "%.8i" '
} 

but the command-line argument isn't used, i.e. the default is only ever used. I tried escaping the $ as per this answer (e.g. watch -n 10 'squeue -p \${1:-default} -o "%.8i" '), but that didn't work either.

Any help appreciated.

1 Answers1

6

When things are in single quotes no variable expansion happens, try

function queue() {
    watch -n 10 "squeue -p ${1:-default} -o '%.8i'"
} 

so the outer quotes are double, which will then do variable expansion within the string

Eric Renouf
  • 1,894