read的使用 (ex36.sh)

来源:互联网 发布:手机怎样升级4g网络 编辑:程序博客网 时间:2024/06/14 18:29
#!/bin/bash# "Reading" variables.echo -n "Enter the value of variable 'var1': "# The -n option to echo suppresses newline.read var1# Note no '$' in front of var1, since it is being set.echo "var1 = $var1"echo# A single 'read' statement can set multiple variables.echo -n "Enter the values of variables 'var2' and 'var3' "echo =n "(separated by a space or tab): "read var2 var3echo "var2 = $var2      var3 = $var3"#  If you input only one value,#+ the other variable(s) will remain unset (null).exit 0

[root@localhost shell]# ./ex36.sh
Enter the value of variable 'var1': 22
var1 = 22

Enter the values of variables 'var2' and 'var3' =n (separated by a space or tab):
22 33
var2 = 22      var3 = 33