欢迎光临散文网 会员登陆 & 注册

Shell 输入输出 字符串输入

2023-08-12 07:26 作者:小步2023  | 我要投稿

详情地址:  https://www.xiaobuteach.com/shell/io/string.html?from=bili

Shell 输入输出 字符串输入

回顾

前面我们介绍了输入的3种位置:键盘、文件、输出命令的输出结果;

1)从键盘输入

read -p "input name:" name

2)从文件获取输入

read -p "input name:" name < data1.txt

3)输出命令的输出结果作为输入

echo "xt" | (read name ; echo $name)

单行文本输入<<<

本节介绍第4种位置:字符串输入。直接设置文本输入。

4)直接把字符串作为read的输入

read name <<< "xiaobuteach.com  00"

<<<,称为"here string"技术,适用于单行字符串输入。


多行文本输入<<EOF

多行输入:here document

输入命令 <<EOF 第1行内容 … 第n内容 EOF

<<EOF是固定写法;

输入最后的EOF回车,自动结束命令。


例:

[root@xiaobuteach c03io]# read name <<EOF > 1111 > 2222 > 333333 > 444 > EOF

>表示回车后的换行显示,不需要手动录入。


Shell 输入输出 字符串输入的评论 (共 条)

分享到微博请遵守国家法律