Я нашел синтаксис, как показано ниже.Что означает ## */в unix?
${VARIABLE##*/}
что смысл ##*/
в этом?
Я знаю значение */
в ls */
, но не знаю, что выше синтаксис делает.
Я нашел синтаксис, как показано ниже.Что означает ## */в unix?
${VARIABLE##*/}
что смысл ##*/
в этом?
Я знаю значение */
в ls */
, но не знаю, что выше синтаксис делает.
Этот пример станет ясно:
VARIABLE='abcd/def/123'
echo "${VARIABLE#*/}"
def/123
echo "${VARIABLE##*/}"
123
##*/
является зачистки самый длинный матч из либо следуют/
от начала ввода.#*/
является зачистка короткого матча из либо с последующим/
от начала ввода.PS: Используя все имена переменных капитала не считается очень хорошей практикой в Unix оболочки. Лучше использовать variable
вместо VARIABLE
.
От man bash
:
${parameter#word}
${parameter##word}
Remove matching prefix pattern. 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 pat‐
tern (the ``##'' case) deleted. If parameter is @ or *, the
pattern removal operation is applied to each positional parame‐
ter in turn, and the expansion is the resultant list. If param‐
eter 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.
Этот вопрос не соответствует теме, потому что речь идет об использовании Unix, принадлежит http://unix.stackexchange.com – Raptor
Возможный дубликат http://stackoverflow.com/questions/14523512/what-does-mean -индекс – ymonad