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 Answer 1

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

1
  • This affords one to make a "watch function" which watches user-made function with argument. I found that it is possible to make a watch function (queue() in this case) which runs watch and user-made function (squeue, in this case) which gets its own argument from watch function (queue()). Apr 26, 2023 at 4:29

You must log in to answer this question.

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