Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I know that I can run the following command

ls Some{File,Folder}

And it is equivalent to running this:

ls SomeFile SomeFolder

(I also use it a lot for things like mv place_{a,b})

However, I was wondering if there was a different shortcut where I could do something like this:

run-command --a --whole --lot --of --flags parameter a; \
     run-command --a --whole --lot --of --flags parameter b

And I only had to type run-command --a --whole --lot --of --flags parameter {a,b} or something similar.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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

Perhaps a for loop?

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

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

share|improve this answer
or if you have a lot you want to run you can use bash expansion like so for x in {a..z}; do ; run-command --a --whole --lot --of --flags parameter $x ; done – h3rrmiller Jan 9 '13 at 18:11
What goes there can be a space separated list generated in many ways. So yeah, {a..z}, *.pdf, $(find ...)... – njsg Jan 9 '13 at 18:34
I don't know why my mind didn't jump to loops. Thanks! This will probably be what I use. The function idea is good, but I like this better. – ashays Jan 10 '13 at 7:21

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
share|improve this answer

There is alias command in bash:

$ alias shotcommand='run-command --a --whole --lot --of --flags parameter'

The usage is: $ shotcommand a

share|improve this answer
There are also functions, if the code is a bit more complex :-) – njsg Jan 9 '13 at 18:32
This solution only works if my changing parameter happens to be the last one, correct? – ashays Jan 9 '13 at 19:41
Yes. You are right. – dchirikov Jan 9 '13 at 19:45

You can perform substitutions in the previous command. This won't work with your {a, b} example, because all instances of 'a' will be replaced with a 'b'. But imagine you want to execute the following commands:

run-command --a --whole --lot --of --parameter --format xml
run-command --a --whole --lot --of --parameter --format son

You can do it with

run-command --a --whole --lot --of --parameter --format xml

Bash will do the substitution and run

run-command --a --whole --lot --of --parameter --format json

Use gs (global substitution) to perform several substitution, not only one.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.