bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
echo "BASH VERSION --- $BASH_VERSION"
echo "bmajor ----- $bmajor"
echo "bminor ----- $bminor"
prints,
BASH VERSION --- 4.2.46(1)-release
bash --- 4.2
bmajor ----- 4
bminor ----- 2
I normally use curly brackets, {} to work with arrays. I see here, they are used for pattern matching.
How these values, ${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} are evaluated? And what does the special characters, *, ., # inside {} mean?
%,%%,#, and##inside${...}, so I'm just answering the rest here. - The*is a shell regexp meta-character ("arbitrary string") in this context. The.is just a literal dot. - The${...}syntax is also advantageous if you want to concatenate variables with literal strings, as in${var}_extwhich is different from$var_ext(the latter would actually mean${var_ext}). - Shells likeksh,bash,zsh, support also yet more expressions (non-POSIX), like${var:pos}and${var:pos:len}. – Janis Jun 07 '15 at 04:20