Что означает этот синтаксис bash? ETL_PORT=“${ETL_PORT:-6090}” [дубликат]

-имя принимает шелл-шаблон, а не регулярное выражение. Вам не нужно и не следует избегать . . Просто используйте:

 find ~+ -name '*.h'

0
15.06.2017, 23:54
1 ответ

Конструкция ${var:-val}будет использовать значение по умолчанию val, если переменная varне установлена ​​во время этого вызова. Это всего лишь одно из многих удобных расширений параметров. У меня есть скрипт, который сгенерирует эту полезную шпаргалку:

${V}             Base string                     |reallyextremelylongfilename.ext
  --- Default substitutions ---
${nullvar}       Provided example case           |
${#nullvar-def}  Default value if unset or null  |def
${#nullvar:-def} Default value if unset          |def
  --- Default assignments ---
${1}             Provided example case           |
${$1=def}        Default value if unset or null  |def
${$1:=def}       Default value if unset          |def
  --- String metadata ---
${#V}            String length                   |31
  --- Substring extraction ---
${V:6}           Substring from position         |extremelylongfilename.ext
${V:6:9}         Substring with length from pos. |extremely
  --- Substring deletion ---
${V#*a}          Delete shortest prefix match    |llyextremelylongfilename.ext
${V##*a}         Delete longest prefix match     |me.ext
${V%e*}          Delete shortest suffix match    |reallyextremelylongfilename.
${V%%e*}         Delete longest suffix match     |r
  --- Substring replacement ---
${V/long/short}  Replace first match             |reallyextremelyshortfilename.ext
${V/#r*a/REA}    Replace prefix match            |REAme.ext
${V/%.e*/.dat}   Replace suffix match            |reallyextremelylongfilename.dat
${V//e/II}       Replace all matches             |rIIallyIIxtrIImIIlylongfilIInamII.IIxt
  --- Other handy things ---
${V?Message}     exit 1 with 'Message' output if V is not set or is null
${V:?Message}    exit 1 with 'Message' output if V is not set
${V+Value}       If V is set, use 'Value', otherwise null
4
28.01.2020, 02:19

Теги

Похожие вопросы