3

I was wondering if there is a way to specify a mutual param for X amount of commands. E.g.

sudo cmd1 cmd2 cm3 \ --help

this obviously doesn't work, but I haven't seen anything in the manual. I'm assuming it can't be done, but didn't rule it out completely. If it doesn't exist, how can I go about making it?

7

You'd have to use a loop:

for cmd in cmd1 cmd2 cmd3; do
    "$cmd" --help
done

Or write a little function for it (add this to your shell's initialization file, ~/.bashrc if using bash):

runWithParam(){
    param="$1"
    shift
    for cmd; do 
      "$cmd" "$param"
    done
}

Then, run it with the parameter as the first parameter of the function:

runWithParam --help cmd1 cmd2 cmd3

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.