Take the 2-minute tour ×
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
add comment

3 Answers

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
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

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

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
add comment

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
add comment

Your Answer

 
discard

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.