How to run a command multiple times with different parameters?

Issue

Is it possible to run a command multiple times with different parameters?

Something like:

sudo apt-get install asd && install qwe && remove ert && autoremove && autoclean

Solution

If you are working from the command line, you can probably use the following: once you ran command parameter1, repeat command with parameter2 instead typing:

^paramater1^parameter2

Example

I have two files: a1 and a2. Let’s ls -l the first:

$ ls -l a1
-rw-r--r-- 1 me me 21 Apr 21 16:43 a1

Now let’s do the same for a2:

$ ^a1^a2
ls -l a2                # bash indicates what is the command being executed
-rw-r--r-- 1 me me 13 Apr 21 16:43 a2

You can find more tricks like this in What is your single most favorite command-line trick using Bash?.

Answered By – fedorqui

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published