#!/bin/bash
function input {
echo "输入不能为空"
local buf=""
read -p $1 buf
echo $buf
}
name=$(input "请输入姓名")
echo $name
#!/bin/bash
function input() {
local buf=""
while true; do
read -p "$1" buf
if [ -z "$buf" ]; then
echo "输入不能为空,请重新输入。" >&2
else
break
fi
done
echo $buf
}
user=$(input "用户名:")
echo $user