美文网首页
Linux 命令之 read

Linux 命令之 read

作者: Manchangdx | 来源:发表于2018-10-28 21:08 被阅读0次

read 命令用于在标准输入中读取数据并赋值给参数

简单的例子:

bash-3.2$ read a
hello world
bash-3.2$ echo $a
hello world
bash-3.2$ read a b  # 可以同时为多个变量赋值,输入值用空格分隔
hello world
bash-3.2$ echo $a
hello
bash-3.2$ echo $b
world

-p 选项指定提示语:

bash-3.2$ read -p '输入一个数字:' num
输入一个数字:123
bash-3.2$ echo $num
123

-r 选项转义 \ 反斜杠为普通字符:

bash-3.2$ cat a.txt
hello\nworld
bash-3.2$ read a < a.txt
bash-3.2$ echo $a
hellonworld
bash-3.2$ read -r a < a.txt
bash-3.2$ echo $a
hello\nworld

-a 选项创建数组:

bash-3.2$ read -a var
a b c d e
bash-3.2$ echo ${var[*]}
a b c d e

相关文章

  • Linux命令之文件管理 (四十六)

    Linux read 命令 inux read命令用于从标准输入读取数值。 read 内部命令被用来从标准输入读取...

  • Linux 命令之 read

    read 命令用于在标准输入中读取数据并赋值给参数 简单的例子: -p 选项指定提示语: -r 选项转义 \ 反斜...

  • Linux read命令

    read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量。 read后面的变量var可...

  • 常用的 shell 工具整理

    1.tldr- 查看 linux命令帮助(Too long, Don't read) tldr ssh 2.aut...

  • linux文件访问权限

    参考 Linux 简单修改权限命令 Linux权限详解 命令之 chmod:修改权限 Linux命令:修改文件权限...

  • iptables命令详解

    linux命令之iptables 1、iptables命令简介 iptables命令是Linux上常用的防火墙软件...

  • Linux命令学习之:echo命令

    Linux命令学习之:echo命令 简介 linux的echo命令, 在shell编程中极为常用, 在终端下打印变...

  • Linux

    有一个非常完整的Linux的教程 http://man.linuxde.net/read 整数比较: 命令的间逻辑...

  • Linux基础篇之-常见Linux命令整理02

    继上篇文章 Linux基础篇之-常见Linux命令整理01 之后,继续整理总结 Linux 常见命令。本篇文章主要...

  • top命令详解

    linux命令之top 1、top命令简介 top命令是动态查看进程变化,监控linux的系统状况;它是常用的性能...

网友评论

      本文标题:Linux 命令之 read

      本文链接:https://www.haomeiwen.com/subject/unbmtqtx.html