读取用户输入

选择性输入,例如yes or no

密码输入,不适合回显

read命令读取用户输入,输入的内容放到变量里

read name

echo "read name, name is $name"

read age

echo "read age, age is $age"

read命令的返回值,只有输入ctrl+d才会返回非0

read name

echo $?

read -p选项可提示用户输入啥内容

read -p "Please input your name: " name

echo "read name, name is $name"

read -p "Please input your age: " age

echo "read age, age is $age"

read -s选项输入密码

read -s -p "Please input your password: " mypwd

echo "read pwd, pwd is $mypwd"

更改nginx安装脚本,支持输入安装目录

read -p "Please input you installpath: " installpath

if [ -e "$installpath" ];then

  echo "nginx is installed. exit script"

  exit 1

fi

nginxdownloadurl="http://nginx.org/download/nginx-1.12.2.tar.gz"

yum -y install wget gcc pcre pcre-devel zlib zlib-devel

cd /usr/local/src/

wget "$nginxdownloadurl"

tar -zxvf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --prefix=$installpath && make && make install

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐