2022-10-30 416
我们知道,在Shell中接收传入的参数有两种方式。一种是通过脚本进行参数传递,另外一种是通过read来接收传入的参数。通过脚本来传递参数的简单示例如下:
# 通过脚本来传递,这里$0指脚本名,$1为第一个参数,$2为第二个参数
[root@host ~]# ./script.sh 1 2
Total = 3
[root@host ~]# vim script.sh
#!/bin/bash
function add() {
total=$(expr $1 + $2)
echo -e "Total = $total"
}
add $1 $2
再来看通过read来接收传入的参数,先看read的基本格式:
read [-rs] [-a ARRAY] [-d delim] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [var1 var2 var3……]
[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"
从上面一个例子,基本上囊括了上面的大部分常用功能,特别是-p,-n,-t,-s等参数,可以很好的学习read这个命令
总结
以上所述是小编给大家介绍的一条命令让你明白shell中read命令的常用参数,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持! 如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
原文链接:https://77isp.com/post/5367.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态