You can also set variables to be read-only, meaning they can't be changed.
readonly MAX=10 |
Set the variable called MAX to the value of 10, then you tried:
MAX=20 |
the shell would give the error:
bash: MAX: readonly variable |
For the simple reason, that by saying something is readonly, you cannot change it afterwards. The only way to undo the readonly, is to kill the shell.
Once you've made a variable readonly, you can't even unset it
unset variablename |
is the syntax to unset a variable
unset MAX |
the shell will give another error:
bash: unset: MAX: cannot unset: readonly variable |
So readonly is a way to create a readonly variable - no rocket science there.
Set a variable POPPINS, and then perform the following parameter substitutions. Obviously try to get the answers BEFORE heading for you Linux machine.
POPPINS='supercalifragilisticexpialidocious'
echo ${POPPINS:=Mary was here}
echo ${POPPINS%a*}
unset POPPINS; echo ${POPPINS:-JulieAndrews}
POPPINS='supercalifragilisticexpialidocious'; echo ${POPPINS#s??e}
echo ${POPPINS%%f*s}
echo ${POPPINS%c*s}
echo ${POPPINS:6:10}
echo ${#POPPINS}