linux script $,linux – 这在shell脚本中是什么意思SCRIPTNAME =“${0 ## * /}”?
此代碼來(lái)自apache2服務(wù)啟動(dòng)腳本.
這是什么意思?
SCRIPTNAME="${0##*/}"
解決方法:
它找到正在運(yùn)行的腳本的名稱,刪除其目錄.例如,如果腳本是/etc/init.d/httpd,那么這將設(shè)置SCRIPTNAME = httpd.
$0或${0}是正在執(zhí)行的腳本的名稱. ##運(yùn)算符用于刪除與模式* /匹配的任何前導(dǎo)字符串. *是通配符,因此* /表示“任何字符串后跟正斜杠”.
這樣做的效果是從$0中刪除任何前導(dǎo)目錄名稱,只留下腳本的名稱.
來(lái)自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.
標(biāo)簽:linux,sh
來(lái)源: https://codeday.me/bug/20190902/1790603.html
總結(jié)
以上是生活随笔為你收集整理的linux script $,linux – 这在shell脚本中是什么意思SCRIPTNAME =“${0 ## * /}”?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: android版本相机权限,Androi
- 下一篇: u盘插入linux系统没有反应_linu