0

I have about 6 programs I want to run one after the other. They all are in different directories with their respective data. I would like help with a script that I can use to run each program in a specific order.

This is because the output of the previous run is the input of the next run.

4

There are 2 ways to "chain" programs together. If you're attempting to chain them together so that the output from the first is passed to the second then you're looking to use what's called a pipe. The other method simply runs one program after another.

pipes example

Here we're taking the output from the first command and passing it through a pipe, (|) to a second command.

$ echo "output from 1" | grep 1
output from 1

The output is being displayed on the screen by the grep command.

commands in series example

Here we're running one command followed by another.

Example

#!/bin/bash

echo 1
echo 2

Put the above in a file called mycmds.bash, make it executable, and run it:

$ chmod +x mycmds.bash
$ ./mycmds.bash
1
2

You can also make use of subshells if you like, to run a series of commands at the prompt, and capture their output to a file. This will run the commands in the same fashion as the shell script method above.

Example

just running commands

$ (echo 1; echo 2; echo 3)
1
2
3

capturing their output

$ (echo 1; echo 2; echo 3) | grep 3
3

capturing their output to a file

$ (echo 1; echo 2; echo 3) | tee mycmds.log
1
2
3

$ cat mycmds.log 
1
2
3
  • @Abraham - glad to hear it. If you're issues been resolved please mark this as the accepted answer so others know you're all set. – slm Sep 4 '13 at 23:29
0

You write the first program on the first line.

You write the second program on the second line.

And you repeat.

0

Your question is difficult to understand. Are you looking for pipes?

If you write

program1 --option1 | program2 --option2

then the output of the command program1 --option1 is fed as input to the command program2 --option2.

You can chain more than two programs in this way. You can put a newline after each pipe symbol if the line becomes too long.

pre-treatment file1.input file2.input file3.input |
some-processing --option=value --other-option |
more-processing |
analyze this --and that |
grep 'interesting stuff'    

See what is meant by connecting STDOUT and STDIN? for a visual explanation of the pipe metaphor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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