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
?
Method #1: Using the Semicolon Operator Here, you can have as many commands as you want to run in parallel separated by semicolons.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With