日期: 2020-02-12 08:15:04
我们知道,在Shell中接收传入的参数有两种方式。一种是通过脚本进行参数传递,另外一种是通过read来接收传入的参数。通过脚本来传递参数的简单示例如下:
[root@host ~]# ./script.sh 1 2Total = 3[root@host ~]# vim script.shfunction 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.shread -n10 -t30 -r -s -d $ -p "Enter Password:" passwordecho -e "\nThe password your input is:$password"
从上面一个例子,基本上囊括了上面的大部分常用功能,特别是-p,-n,-t,-s等参数,可以很好的学习read这个命令
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对ASPKU源码库的支持。