之前学过输出重定向:

将输出改向(到某一文件)

[root@tian diry]# cat > 1.txt
这是1.txt
[root@tian diry]# cat 1.txt
这是1.txt

 这里将标准输出流(显示器)改向到文件1.txt,所以cat 1.txt可以看到改向内容

现在我有个疑惑

  prog < infile > outfile

 我好奇符号“<”,经过查询和实验;它叫输入重定向,作用是将后面的作为输入传给前面的程序prog(ram)

[root@tian diry]# cat 2.txt 
ls -l
[root@tian diry]# sh < 2.txt 
总用量 12
-rw-r--r--. 1 root root  12 10月 19 15:07 1.txt
-rw-r--r--. 1 root root   6 10月 19 14:59 2.txt
-rw-r--r--. 1 root root 160 10月 19 14:53 outfile
-rw-r--r--. 1 root root   0 10月 19 14:48 profile

这里将文件2.txt的内容作为输入重定向给sh,其结果等同于先键入sh回车,再输入ls -l

[root@tian diry]# sh
sh-4.2# ls -l
总用量 12
-rw-r--r--. 1 root root  12 10月 19 15:07 1.txt
-rw-r--r--. 1 root root   6 10月 19 14:59 2.txt
-rw-r--r--. 1 root root 160 10月 19 14:53 outfile
-rw-r--r--. 1 root root   0 10月 19 14:48 profile
sh-4.2# 

 

posted on 2022-10-19 15:31  贾肃  阅读(39)  评论(0)    收藏  举报