Can I execute nested or chained commands in UNIX shell?

Osama Ahmad picture Osama Ahmad · Sep 19, 2010 · Viewed 24.8k times · Source

Can I execute command within another command in UNIX shells?

If impossible, can I use the output of the previous command as the input of next command, as in:

command x then command y,

where in command y I want use the output of command x?

Answer

Colin Hebert picture Colin Hebert · Sep 19, 2010

You can use the backquotes for this.

For example this will cat the file.txt

cat &graveecho file.txt&grave

And this will print the date

echo the date is &gravedate&grave

The code between back-quotes will be executed and be replaced by its result.