Reputation: 57
How can I concatenate the output of pwd
and ls
and add it to a file called f1? This is not working:
pwd, ls > f1
Upvotes: 3
Views: 5440
Reputation: 9285
Maybe you looking for doing something harder but file appending is a simple solution:
pwd >> f1
ls >> f1
If you prefer chepner's or Mark Setchell's answer, here's an explanation:
You can use subshell with parenthesis:
( pwd; ls; ) > f1
Or subcommand:
{ pwd; ls; } > f1
With subshell, parent shell won't have access to children environment. Variable aren't kept because a new orphan process is created.
And with subcommand initialized variable are kept and usable with parent.
Both have parent environment.
Reference:
Upvotes: 2
Reputation: 208077
Saves a semi-colon and 2 spaces, costs a process vs @chepner :-)
(pwd;ls) > f1
Upvotes: 1