zoukankan      html  css  js  c++  java
  • read 命令详解

    read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量

    语法选项

    -p  read –p “提示语句”,则屏幕就会输出提示语句,等待输入,并将输入存储在REPLY中
    -n  read –n 个数
    -t  read –t 时间
    -s  read -s 选项能够使read命令中输入的数据不显示在监视器上

    例子

    1. 从标准输入读取输入并赋值给变量
    [xiess@layzj022301 ~]$ read readfile
    hello,world!!welcome to shell
    [xiess@layzj022301 ~]$ echo $readfile
    hello,world!!welcome to shell
    [xiess@layzj022301 ~]$
    1. 等待一组输入,每个单词之间使用空格隔开,直到回车结束,并分别将单词依次赋值给这三个读入变量。
    [xiess@layzj022301 ~]$ read frist second third
    the_one the_two the_three
    [xiess@layzj022301 ~]$ echo "$frist" "$second" "$third"
    the_one the_two the_three
    [xiess@layzj022301 ~]$
    1. REPLY示例
    [xiess@layzj022301 ~]$ read -p "Enter your name: "
    Enter your name: admin_xiess
    [xiess@layzj022301 ~]$ echo $REPLY
    admin_xiess
    [xiess@layzj022301 ~]$
    1. 关闭显示
    [root@cinder01 ~]# cat readfile.sh 
    #!/bin/bash
    read -s -p "Enter your password: " password
    echo
    echo "your password is $password"
    [root@cinder01 ~]# chmod a+x readfile.sh 
    [root@cinder01 ~]# sh readfile.sh 
    Enter your password: 
    your password is 123456
  • 相关阅读:
    苹果输入手机号变用户的名字
    iOS 关于UITableView的黑科技
    iOS 详解NSObject协议
    iOS 用xib自定义View
    iOS 关于定位你该注意的那些事
    iOS 内存泄漏
    Swift应用案例 2.闭包入门到精通
    Swift应用案例 1.无限轮播
    多库共存-冲突问题
    多库共存-冲突问题
  • 原文地址:https://www.cnblogs.com/xieshengsen/p/6666972.html
Copyright © 2011-2022 走看看