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
- 下一篇: html如何将标题置顶,.Html 头部