variables

variables


${MYVAR#pattern}     # delete shortest match of pattern from the beginning
${MYVAR##pattern} # delete longest match of pattern from the beginning
${MYVAR%pattern} # delete shortest match of pattern from the end
${MYVAR%%pattern} # delete longest match of pattern from the end

${MYVAR:3} # Remove the first three chars (leaving 4..end)
${MYVAR::3} # Return the first three characters
${MYVAR:3:5} # The next five characters after removing the first 3 (chars 4-9)

${MYVAR/search/replace}

примеры:

[werwolf@work] ~  
MYVAR='123 abc dog'

[werwolf@work] ~
echo $MYVAR
123 abc dog

[werwolf@work] ~
echo ${MYVAR#1}
23 abc dog

[werwolf@work] ~
echo ${MYVAR%og}
123 abc d

[werwolf@work] ~
echo ${MYVAR:2}
3 abc dog

[werwolf@work] ~
echo ${MYVAR/dog/cat}
123 abc cat

Содержание