Shortening the 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
+3
source share
2 answers

What about:

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

EDIT:

The designation {...}instructs bashto run these commands in the current shell, and not use a subshell, as it would be when using notation (...). 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 comamnds, but the notation is (...)easier to use, since you do not need to manually return all the changes after that:

( whereis python; date; who ) > test.txt
+3
source
(whereis python; date; who) >test.txt
+1
source

Source: https://habr.com/ru/post/1781099/


All Articles