Я побежал в Баш скрипт сегодня, он имеет следующие ведущие линии:Как изменить параметр shell bash в этом выражении?
$ cat -n deploy.sh
1 #!/bin/bash
2
3 # Usage: ./deploy.sh [host]
4
5 host="${1:[email protected]}"
6
7 # The host key might change when we instantiate a new VM, so
8 # we remove (-R) the old host key from known_hosts
9 ssh-keygen -R "${host#*@}" 2> /dev/null
[...]
Line 5 легко. Линия 9 достала меня. Я «верю», что это своего рода расширение параметров bash, но, читая man-страницу, я больше не уверен.
Цитируя Баш человека страницы:
${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.
Допустим, я просто запустить сценарий как этот
./deploy.sh
без какого-либо входного параметра, а затем по линии 5, хост будет установлен в убунту @ example.com. Затем доходит до строки 9, в игру вступает $ {host # * @}. # Запускает подстановку с использованием расширенного * @. Но к чему это распространяется? Это не слово, которое используется на странице руководства?
Любые советы/подсказки.
Zack
попробуйте добавить 'echo '$ {host # * @}" ' – perreal