1 read 用法
基本读取
[root@foundation77 mnt]# read a westos [root@foundation77 mnt]# echo $a westos
[root@foundation77 mnt]# read -p "请输入密码:" 请输入密码:
[root@foundation77 mnt]# vim read.sh [root@foundation77 mnt]# cat read.sh #!/bin/bash read -p "输入你的姓名:" a echo “出门右转 $a” exit 0 [root@foundation77 mnt]# sh read.sh 输入你的姓名:张 “出门右转 张” [root@foundation77 mnt]#
[root@foundation77 mnt]# read -p "请输入密码:" 请输入密码:^C # 此时如果不输入内容会一直等待 [root@foundation77 mnt]# read -t 3 -p "请输入密码:" #只等待3秒,3秒后自动退出 请输入密码:[root@foundation77 mnt]#
-s 隐藏输入:如果输入的内容需要隐藏,可以加-s 不显示。
[root@foundation77 mnt]# read -p "请输入密码:" 请输入密码:1234 [root@foundation77 mnt]# read -s -p "请输入密码:" 请输入密码:[root@foundation77 mnt]#
文章来源: shell的read用法