Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortening Bash output command

Is there a more efficient way to output a command than this:

whereis python > test.txt;date >> test.txt;who >> test.txt
like image 772
Switchkick Avatar asked Dec 01 '25 05:12

Switchkick


2 Answers

How about:

{ whereis python; date; who; } > test.txt

EDIT:

The {...} notation instructs bash to launch these commands in the current shell, rather than use a subshell as would be the case if the (...) notation was used. It is slightly more efficient as it avoids creating a new process.

If you want to temporarily change the environment (working directory, variables etc) for the comamnds, though, the (...) notation is simpler to use, since you don't have to manually revert all changes afterwards:

( whereis python; date; who ) > test.txt
like image 106
thkala Avatar answered Dec 03 '25 18:12

thkala


(whereis python; date; who) >test.txt
like image 23
khachik Avatar answered Dec 03 '25 18:12

khachik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!