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.


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

| improve this answer | |

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.