用子Shell的方式读取管道相连的命令的输出:
[student@myhost ~]$ a=$(ls | cat -n)
[student@myhost ~]$ echo $a
1 4 2 5 3 a 4 aout 5 b
用反引用方式读取管道相连的命令的输出:
[student@myhost ~]$ b=`ls | cat -n`
[student@myhost ~]$ echo $b
1 4 2 5 3 a 4 aout 5 b
子Shell本身是一个独立的进程,用()可以创建一个子Shell,所有改变仅限于子Shell:
[student@myhost ~]$ cat c
pwd;
(cd /);
pwd;
[student@myhost ~]$ bash c
/home/student
/home/student