1. Piping "|"
ls | Cat-n > OUT.txt
2. Child shell
2.1 Child Shell Description
You can use the () operator to define a child shell in a shell script
#/bin// ; ls) pwd
Execution results
Description: Does not have any effect on the current shell when the command executes in a child shell
2.2 Getting data from a child shell
cmd_output=$ (COMMANDS)
out=$ (ls-l | cat-n)
#!/bin/bashout=$ (lscat -N)echo $out
Output Result:
The problem: the return key between rows and rows is gone. This is obviously the result we don't want.
Workaround: Enclose the result of the child shell in double quotes, preserving line breaks
#!/bin/bashout=$ (lscat -N)echo $outout="$ ( Ls-l | cat-n)"echo $out
Execution Result:
What the heck!!! There is no change. Is it wrong to write in the book?!
Finally found the answer to the question on the Internet: IFS (internal domain delimiter)
IFS Details: http://www.2cto.com/os/201504/394478.html
The IFS is set to "\ n" line breaks.
#!/bin/bashout=$ (lscat -N)echo $outIFS="\ n "out ="$ (ls-l | cat-n)"echo $out
3. Anti-citation (not a single quote)
out.txt= ls | Cat-n
Other operations are the same as child shells
Delivery of data between commands in the shell