Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

一条命令让你明白shell中read命令的常用参数

我们知道,在Shell中接收传入的参数有两种方式。一种是通过脚本进行参数传递,另外一种是通过read来接收传入的参数。通过脚本来传递参数的简单示例如下:

# 通过脚本来传递,这里
[root@host ~]# ./script.sh 
Enter Password:
The password your input is: Test@1234\
[root@host ~]# vim script.sh
#!/bin/bash
read -n10 -t30 -r -s -d $ -p "Enter Password:" password
echo -e "\nThe password your input is:$password"
指脚本名,为第一个参数,为第二个参数 [root@host ~]# ./script.sh 1 2 Total = 3 [root@host ~]# vim script.sh #!/bin/bash function add() { total=$(expr + ) echo -e "Total = $total" } add

再来看通过read来接收传入的参数,先看read的基本格式:

read [-rs] [-a ARRAY] [-d delim] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [var1 var2 var3......]

  • -p 提示语句,后面接输入提示信息,这里为'Enter Password: '
  • 从上面一个例子,基本上囊括了上面的大部分常用功能,特别是-p,-n,-t,-s等参数,可以很好的学习read这个命令

    [+++]

    以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

    )
    File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
    File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
    File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
    指脚本名,为第一个参数,为第二个参数 [root@h" /> 指脚本名,为第一个参数,为第二个参数 [root@h"> 一条命令让你明白shell中read命令的常用参数_软件运维_内存溢出

    阅读 32

    一条命令让你明白shell中read命令的常用参数,第1张

    一条命令让你明白shell中read命令的常用参数

    我们知道,在Shell中接收传入的参数有两种方式。一种是通过脚本进行参数传递,另外一种是通过read来接收传入的参数。通过脚本来传递参数的简单示例如下:
    
    
    # 通过脚本来传递,这里
    [root@host ~]# ./script.sh Enter Password: The password your input is: Test@1234\ [root@host ~]# vim script.sh #!/bin/bash read -n10 -t30 -r -s -d $ -p "Enter Password:" password echo -e "\nThe password your input is:$password"

    指脚本名,为第一个参数,为第二个参数 [root@host ~]# ./script.sh 1 2 Total = 3 [root@host ~]# vim script.sh #!/bin/bash function add() { total=$(expr + ) echo -e "Total = $total" } add

    再来看通过read来接收传入的参数,先看read的基本格式:

    read [-rs] [-a ARRAY] [-d delim] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [var1 var2 var3......]
    • -p 提示语句,后面接输入提示信息,这里为'Enter Password: '
    • -n 参数个数,有时候要限制密码长度,或者其他输入长度限制,比如[Y/N],只输入输入一位,-n1
    • -s 屏蔽回显,屏幕上不显示输入内容,一般用于密码输入
    • -t 等待时间,这里设置30秒,30秒内未输入或者输入不全,终止
    • -d 输入界限,这里是$,输入到$,自然终止输入
    • -r 屏蔽特殊字符\的转译功能,加了之后作为普通字符处理
    总结

    从上面一个例子,基本上囊括了上面的大部分常用功能,特别是-p,-n,-t,-s等参数,可以很好的学习read这个命令

    以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

    欢迎分享,转载请注明来源:

    内存溢出

    原文地址:

    http://outofmemory.cn/yw/902889.html
    一条命令让你明白shell中read命令的常用参数
    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    code code 管理员组
    Linux统计一个文件中特定字符个数的方法
    上一篇
    2022-05-15
    Linux安装Python虚拟环境virtualenv的方法
    2022-05-15

    发表评论
    请登录后评论... 登录
    提交

      评论列表(0条)
    保存
    {label} {label} 指脚本名,为第一个参数,为第二个参数[root@h', author : 'code', cat_name : '软件运维', time_y_m : '2022年05月', time_d : '15', site_motto : '内存溢出' }; {script} {script}