Rerunning the same command with a different parameter

Assuming that you are using the GNU bash or something similar:

Perhaps a for loop?

for x in a b
do
    run-command --a --whole --lot --of --flags parameter $x
done

which can also be written in one line as for x in a b; do run-command --a --whole --lot --of --flags parameter $x ; done


If you aren't scripting this and just want to run it easily on a command line, the xargs command is probably what you are looking for.

xargs will take a bunch of content from the standard input, and use it as arguments for a command, running that command multiple times if needed.

Try the following:

echo -n parameter a,parameter b | xargs -n 1 -d , run-command --a --whole --lot --of --flags

Echo's -n flag avoids printing a trailing new line character (caused issues with some commands while passing parameters through).

In this example, you are simply giving xargs the permutations you want it to run.

The -n 1 flag to tell xargs to use just 1 of the arguments per run.

The -d , flag tells xargs to look for a "," on the input as the deliminator between arguments to run. (Note that if the argument has a "," in it you will need to change this to something else. If your arguments have no spaces in them you can omit this flag altogether.)

See man xargs for more info.


You can also use a function, which doesn't limit you to having your changing argument at the end:

runcom() { run-command --a --whole --lot --of --flags parameter "$1" ; }

runcom a
runcom b