linux script $,linux – 这在shell脚本中是什么意思SCRIPTNAME =“${0 ## * /}”?
此代码来自apache2服务启动脚本.
这是什么意思?
SCRIPTNAME="${0##*/}"
解决方法:
它找到正在运行的脚本的名称,删除其目录.例如,如果脚本是/etc/init.d/httpd,那么这将设置SCRIPTNAME = httpd.
$0或${0}是正在执行的脚本的名称. ##运算符用于删除与模式* /匹配的任何前导字符串. *是通配符,因此* /表示“任何字符串后跟正斜杠”.
这样做的效果是从$0中删除任何前导目录名称,只留下脚本的名称.
来自man bash:
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the pattern
matches the beginning of the value of parameter, then the result of the expansion is the
expanded value of parameter with the shortest matching pattern (the “#” case) or the longest
matching pattern (the “##” case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
标签:linux,sh
来源: https://codeday.me/bug/20190902/1790603.html
总结
以上是生活随笔为你收集整理的linux script $,linux – 这在shell脚本中是什么意思SCRIPTNAME =“${0 ## * /}”?的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android版本相机权限,Androi
- 下一篇: u盘插入linux系统没有反应_linu