Run multiple commands consequently

October 3rd, 2006 mysurface Posted in du, read, Symbol, terminator, while | Hits: 83498 | 6 Comments »

By specified terminator ( ; ) like in C/C++ programming, you can run multiple commands consequently. We usually want to do this when we want to compile and install source code for certain packages.

./configure;make;make install

Bash first execute the configure, then make , consequently will install the package. But bare in mind, bash have no intelligent, if error at configure, the consequent command will still run.

By using terminator, you can make loop into a single line command too. The example shows how to use while loop, read to read directory from a command line and show the directory’s cumulated size.

while read line; do du -sh $line; done <<< `ls -d */ `

Let me explain a bit, I looks like an interesting combo of command.

ls -d */ list only the directories, this feed to read. read is to read any input, for this case it read from the output of ls -d */. It uses <<< to pass its output to read.

line is just a variable to store the output of ls -d */ one by one. $line contain the string of line it store. Observered the do, it does du -sh the "output" one by one.

Actually, this is not a good example. What it does is very redundant, by doing this

du -sh */

you can get the same job done.

If you have a better example to share, please feel no hesitate to comment it.

6 Responses to “Run multiple commands consequently”

  1. [...] As easy as that, you can even passing external value to awk scripts. Depends on how creative you are, you may create a great awk scripts to ease your logs analysis. Related Posts Run multiple commands consequently By specified terminator ( ; ) like in C/C++ programming, you can run multiple commands consequently. We usually want to … [...]

  2. Robb Tolliver Says:

    if you use two ampersands(&) between commands, the next command will only execute if the first one was successful. For example if you type ‘g++ source.C&&a.out’ it will only try to run a.out if the source compiled successfully.

  3. Robb: Thank you, you are right. In this context, putting && makes more sense.

  4. I would like to run two methods Timedelay() and flash() concurrently.

    Do we have any command to run both methods concurrently

  5. What’s up to every body, it’s my first visit of this website; this web
    site carries awesome and truly fine data for readers.

    Feel free to surf to my blog – recorder Screen

  6. With so many choices, students often hesitate
    in making a choice, we at wish to educate and inform students, clear their doubts
    and help them choose the right program at a reputable educational institution. Put a tyrant
    in charge, and free thought and speech disappear. An AA degree in ASL allows you
    to go into work interpreting and educating others — and it can help
    those who are going into social work or psychology. Statistics have shown that homes
    displaying decals stating that the home is protected by an alarm monitoring service
    are less likely to be the victims of burglaries. Is it wise to
    put off spiritual disaster preparedness.

    Feel free to surf to my blog post water purification methods

Leave a Reply