natbob1
natbob1

Reputation: 318

Command quoting in bash function

In trying to create a bash function which accepts arguments and passes them to another command I am encountering a problem in quoting the parameters correctly.

I am defining the following function:

function cluster () {
    dsh -acM -- \'"$@"\';
}

The usage of this command being to translate something like cluster ls -l to dsh -acM -- 'ls -l'.

Thanks for your time.

Upvotes: 0

Views: 57

Answers (1)

chepner
chepner

Reputation: 531075

You can just use

cluster () {
    dsh -acM -- "$*"
}

so that dsh gets a single string for the last argument.

Upvotes: 1

Related Questions