What does this bash syntax means?
Does this mean that ETL_PORT variable will be ETL_PORT if ETL_PORT is set , and otherwise defaults to 6090 if not set?
ETL_PORT="${ETL_PORT:-6090}"
What does this bash syntax means?
Does this mean that ETL_PORT variable will be ETL_PORT if ETL_PORT is set , and otherwise defaults to 6090 if not set?
ETL_PORT="${ETL_PORT:-6090}"
The construct ${var:-val}
will use a default value of val
if the variable var
is unset at the time of that invocation. It's but one of many handy parameter expansions. I have a script that will generate this helpful cheat sheet:
${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