read [OPTION]… [NAME…]
OPTION:
-p ‘PROMPT’ : output the string PROMPT without a trailing newline before attempting to read. 在尝试读取之前,输出字符串提示符,而没有拖尾换行符;
-t TIMEOUT : 指定超时时间;
bash -n /PATH/TO/SOME_SCRIPT 检查脚本语法是否有错误;
bash -x /PATH/TO/SOME_SCRIPT 调试脚本执行;
脚本1:
--------------
#!/bin/bash
#
read -p "Enter a disk special file :" diskfile
[ -z "$diskfile" ] && echo "need a arg." && exit 11
if fdisk -l | grep "^Disk $diskfile" &> /dev/null;then
fdisk -l $diskfile
else
echo "Wrong disk special file."
exit 22
fi
脚本2:
----------------
#!/bin/bash
#
read -p "Enter a user name :" name
[ -z $name ] && echo "need a arg." && exit 11
read -p "Enter $name password.default arg is [password]" Password
[ -z $Password ] && echo "use default arg:password"
if id $name &> /dev/null;then
echo "$name user is already exits."
else
useradd $name
echo "$Password" | passwd --stdin $name &> /dev/null
echo "$name user is not exits.createing now..."
echo
echo "add $name user is finished.passwd is the same witch username"
fi