Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I execute nested or chained commands in UNIX shell?

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?

like image 423
Osama Ahmad Avatar asked Sep 19 '10 14:09

Osama Ahmad


People also ask

How do I run multiple commands in parallel Unix?

Method #1: Using the Semicolon Operator Here, you can have as many commands as you want to run in parallel separated by semicolons.


2 Answers

You can use the backquotes for this.

For example this will cat the file.txt

cat `echo file.txt`

And this will print the date

echo the date is `date`

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

like image 148
Colin Hebert Avatar answered Sep 29 '22 20:09

Colin Hebert


You can do something like;

x=$(grep $(dirname "$path") file)

here dirname "$path" will run first and its result will be substituted and then grep will run, searching for the result of dirname in the file

like image 27
codaddict Avatar answered Sep 29 '22 20:09

codaddict