shell脚本read传递参数

1. 用read获取用户的输入:

 举例:example.sh, 查看:  cat example.sh:

#!/bin/bash

# This is a sample script file.

# Accept user input for demonstration.

#使用read命令将用户的输入保存到变量NAME中

echo -n "Input your name:"

read NAME

#使用echo 命令输出变量

echo "Hello,"$NAME"."

运行上述示例脚本:

#为示例脚本添加可执行权限

# chmod u+x example.sh

#执行示例脚本example.sh

#     ./example.sh

#在提示信息后输入姓名

Input your name: Jhon

Hello,Jhon.

原文地址:https://www.cnblogs.com/guosj/p/4903750.html