On what basis does the role of asterisk keep changing?
CASE 1:
var1=abcd-1234-defg
echo ${var1#*-*} # RESULT: 1234-defg
CASE 2:
stringZ=abcABC123ABCabc
echo `expr match "$stringZ" '\(abc[A-Z]*.2\)'` # RESULT: abcABC12
When and how is the role of asterisk decided?
CASE 3:
path_name="/home/bozo/ideas/thoughts.for.today"
echo ${path_name##/*/} # RESULT : thoughts.for.today
In this case I mistook /
to be playing the role of escape character here, i.e., trying to escape the basic characteristic of *
. Well, I was wrong. So how are the roles of these special characters decided and by whom?
CASE 4:
var1=abcd--1234-defg
echo ${var1#*-*} # RESULT: -1234-defg & i was expecting 1234-defg
The CASE 4 is similar to CASE 1, but with a difference as can be seen abcd--
, and I was expecting 1234-defg
, but the result turned out to be the same as in case 1.
This is how I interpreted *-*
in CASE 4:
The shell would look for everything from the start of the var1 till it finds - OR -- OR ---
Why is my interpretation in the context of CASE 4 incorrect?