shell的logo含义_【shell】怎么理解shell中的 "<" 、 "<<" 、 "< <" 、"<<<" 的含义?

一、说明

大多数 UNIX 系统命令从你的终端接受输入并将所产生的输出发送回​​到您的终端。

一个命令通常从一个叫标准输入的地方读取输入,默认情况下,这恰好是你的终端。

同样,一个命令通常将其输出写入到标准输出,默认情况下,这也是你的终端。

二、输出重定向

重定向一般通过在命令间插入特定的符号来实现。

关于输出重定向,没有多少可说的,比较好理解,不是本文的重点。

如果不熟悉的读者,可以参考:

shell 输入/输出重定向

http://www.runoob.com/linux/linux-shell-io-redirections.html

shell中 1>&2 2>&1 &> 重定向的含义和区别是什么?

https://www.jianshu.com/p/41c304016185

三、输入重定向

输入重定向和输出重定向一样,Unix 命令也可以从文件获取输入。

1.关于 "

语法:

#   command   

注意:输出重定向是大于号(>),输入重定向是小于号(

#  mysql  -u  root   -h 127.0.0.1  -p"MySQL@123"   

#  echo "123456"  > passwd.txt

# passwd  --stdin root  < passwd.txt

2.  关于 "<

"<

Here Documents 是 shell 中的一种特殊的重定向方式,用来将输入重定向到一个交互式 Shell 脚本或程序。

将两个 delimiter(此处是OF,end of file 之意) 之间的内容(document) 作为输入传递给 command。

如果想将输入保存到文件文件中,可以结合输出重定向:

#  cat    << EOF     >>  /etc/profile

EOF

3. 关于 "<<

"<<

Here String是Here Documents 的一个变种。

它由操作符"<<

语法:

#  command <<

注意:单个单词不需要引号引用,中间如果有空格的字符串,则需要引号引用起来。

# echo "123456" | passwd  --stdin  root

# passwd --stdin root  <<< "123456"

# mysql -u root   -e      "select user,host from mysql.user;"

# mysql -u root   <<

# while read line ; do echo $line; done <<< "111 222 333"

4. 关于 "

应该说  "

左边 < 代表左边接受从右边输入,右边

语法:

#   command 

注意:右边的

# while read var; do unset $var; done <

# passwd --stdin root

# mysql -u root <

四、参考

Shell 输入/输出重定向

http://www.runoob.com/linux/linux-shell-io-redirections.html

shell中 1>&2 2>&1 &> 重定向的含义和区别是什么?

https://www.jianshu.com/p/41c304016185

Linux 输入输出(I/O)重定向

https://www.cnblogs.com/divent/p/5773861.html

shell重定向

https://blog.csdn.net/fsx2550553488/article/details/80994277

linux shell输入输出重定向

https://www.xuebuyuan.com/745014.html

shell中while循环的陷阱

https://www.cnblogs.com/f-ck-need-u/p/7431578.html

What is the meaning of  < and << in UNIX /Linux?

https://unix.stackexchange.com/questions/114514/and-in-unix-linux

Correct textual name for <<

https://unix.stackexchange.com/questions/2888/correct-textual-name-for

Here Documents

https://en.wikipedia.org/wiki/Here_document

Here Strings

https://bash.cyberciti.biz/guide/Here_strings

What does "<<

https://www.quora.com/What-does-mean-in-linux-shell-script

What does <<< mean?

https://unix.stackexchange.com/questions/80362/what-does-mean

https://superuser.com/questions/811973/how-to-execute-multiple-multiline-mysql-queries-with-a-shell-script

https://my.oschina.net/u/553266/blog/2935635

https://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators

https://www.gnu.org/software/bash/manual/bashref.html#Redirections

https://unix.stackexchange.com/questions/114514/and-in-unix-linux

https://github.com/qinjx/30min_guides

https://stackoverflow.com/questions/1602904/how-do-you-run-a-single-query-through-mysql-from-the-command-line

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值