JOBS=${JOBS:="-j2"}
dir=${1-/usr/src}
:=
ここでとはどういう-
意味ですか?
それらはある種のデフォルトとして機能すると推測できますが、違いは何ですか?
JOBS=${JOBS:="-j2"}
dir=${1-/usr/src}
:=
ここでとはどういう-
意味ですか?
それらはある種のデフォルトとして機能すると推測できますが、違いは何ですか?
:=
(および関連する)の場合=
、組み込みの':'コマンドを使用して、パラメーターをそれ自体に割り当てることなく、パラメーターを評価することができます。
# Set JOBS=-j2 if JOBS is not set or equal to ""
: ${JOBS:='-j2'}
# Set JOBS=-j2 if JOBS is not set. Don't change if JOBS is already set to ""
: ${JOBS='-j2'}
:-
およびについて-
は、変数の値を変更しないでください。代わりに2番目の値を使用してください。
# Set dir to /usr/src if $1 is not set, but don't set $1 itself
dir=${1-/usr/src}
# Set dir to /usr/src if $1 is not set or set to "", but don't set or change $1
dir=${1:-/usr/src}
man bash
(Parameter Expansion
セクション)は、これらおよび関連する質問に答えます。
抜粋:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parame‐
ter is substituted.
${parameter:=word}
Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. The value of
parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
${parameter:?word}
Display Error if Null or Unset. If parameter is null or unset, the expansion of word (or a message to that effect if word
is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of
parameter is substituted.
${parameter:+word}
Use Alternate Value. If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substi‐
tuted.