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