bash脚本编程之用户交互
- read命令解析
- 从键盘读取变量的值,通常用在shell脚本中与用户进行交互的场合。
- 常用选项:
- -p ‘PROMPT’:指定读取时的提示符
- -t TIMEOUT:指定读取时的等待时间
- bash -n /path/to/some_scripts:检测脚本中的语法错误
- bash -x /path/to/some_scripts:调试执行
- 示例:
#!/bin/bash
# version:0.0.1
# Author:Ivan
# Description:read testing
read -p "Enter a disk special file:"
[ -z "$diskfile" ] && echo "fool" && exit 1
if fdisk -l|grep "^Disk $diskfile" &> /dev/null;then
fidsk -l $diskfile
else
echo "Wrong disk special file."
exit2
fi