Bash - String Manipulation Minus Sign (-) (hyphen) -
this question has answer here:
- usage of :- (colon dash) in bash 2 answers
while looking @ apache run script /etc/init.d/apache2
realise different in string manipulating substring extraction. example:
if [ "${apache_confdir##/etc/apache2-}" != "${apache_confdir}" ] ;
or
if [ -n "${pidtmp:-}" ] && kill -0 "${pidtmp:-}" 2> /dev/null;
the second 1 seems use default values if pidtmp
unset or null didn't find logical in one.
what use of minus sign (-
) in each case? brief explanation helpful.
note:i interested in minus signs in braces , checked :-word
.
it seems me has no real effect. :-
supposed mean: "if not set, use following default value", since nothing follows, afaik has no effect:
- if variable set, default value not taken
- if variable unset, expand "", have happened anyway when using
"${pidtmp}"
.
the use case can imagine make sure expansion contains @ least empty string , not "unset variable" (this makes difference when -u
option in effect).
in bash man page:
${parameter:-word} use default values. if parameter unset or null, expansion of word substituted. otherwise, value of parameter substituted.
and
-u treat unset variables , parameters other special parameters
"@"
,"*"
error when performing parameter expansion. if expansion attempted on unset variable or parameter, shell prints error message, and, if not interactive, exits non-zero status.
Comments
Post a Comment