Linux管道

用子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
posted @ 2022-10-17 19:21  epiphanyy  阅读(7)  评论(0)    收藏  举报  来源