Linux shell之read 用法#!/bin/bash
#read 用来读取屏幕输入或是读取文件内容。
read -p "please input you name: " name #获取输入变量
read -p "please input you age: " age #获取输入变量
echo "you name is $firstname ,age is $age" #输出变量内容#执行结果
[root@sql tmp]# ./read
please input you name: liyang
please input you age: 100
you name is liyang,age is 100
read a <a.txt #从文件a.txt 中获取变量a 的值。
| 格 式 | 含 义 |
| read answer | 从标准输入读取一行并赋值给变量answer |
| read first last | 从标准输入读取一行,直至遇到第一个空白符或换行符。把用户键入的第一个词存到变量first中,把该行的剩余部分保存到变量last中 |
| read | 标准输入读取一行并赋值给内置变量REPLY |
| read –a arrayname | 读入一组词,依次赋值给数组arrayname③ |
(续表)
| 格 式 | 含 义 |
| read -e | 在交互式shell命令行中启用编辑器。例如,如果编辑器是vi,则可以在输入行时使用vi命令③ |
| read –p prompt | 打印提示符,等待输入,并将输入赋值给REPLY变量③ |
| read –r line | 允许输入包含反斜杠③ |
相关阅读:Linux Shell参数替换 http://www.linuxidc.com/Linux/2013-06/85356.htmShell for参数 http://www.linuxidc.com/Linux/2013-07/87335.htmLinux/Unix Shell 参数传递到SQL脚本 http://www.linuxidc.com/Linux/2013-03/80568.htmShell脚本中参数传递方法介绍 http://www.linuxidc.com/Linux/2012-08/69155.htmShell脚本传递命令行参数 http://www.linuxidc.com/Linux/2012-01/52192.htm