Search code examples
linuxbashcommand

How to run a command multiple times with different parameters?


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:

    ^parameter1^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?.