I read "Linux Bible 10th Edition", chapter 7: Writing Simple Shell Scripts, at 149 page, "Parameter expansion in bash" paragraph.
${var:-value}
— If variable is unset or empty, expand this to value.${var#pattern}
— Chop the shortest match for pattern from the front of var’s value.${var##pattern}
- Chop the longest match for pattern from the front of var’s value.${var%pattern}
— Chop the shortest match for pattern from the end of var’s value.${var%%pattern}
- Chop the longest match for pattern from the end of var’s value.
Please, explain to me, how the longest/shortest match is calculated? From right to the left or vice versa?
Also, explain please, how code below is working and how output is calculated
MYFILENAME=”/home/digby/myfile.txt”—Sets the value of MYFILENAME
FILE=${MYFILENAME##*/}—FILE becomes "myfile.txt"
DIR=${MYFILENAME%/*}—DIR becomes "/home/digby"
NAME=${FILE%.*}—NAME becomes "myfile"
EXTENSION=${FILE##*.}—EXTENSION becomes "txt"
Thank you.