How can I concatenate the output of two commands?
3 answers
You may be looking for something more complex, but adding files is a simple solution:
pwd >> f1
ls >> f1
If you prefer Chepner's or Mark Setchell's answer, here's the explanation:
-
You can use a parenthesis subshell:
( pwd; ls; ) > f1
-
Or a subcommand:
{ pwd; ls; } > f1
With a subshell, the parent shell won't have access to the child's environment. The variable is not saved because a new orphan process is being created.
And with the subcommand, the initialized variable is preserved and can be used with parents.
Both have a parent environment.
Link:
+1
source to share