Click to See Complete Forum and Search --> : Pattern matching issue in bash


babu_says
08-06-2003, 05:33 AM
Hi,

I tried the following

[...]$ var1="xyz/abc"
[...]$ echo ${var1%abc}
xyz/
[...]$ echo ${var1%/abc}
xyz
[...]$ echo ${var1%*/}
xyz/abc


I expected a "xyz" for the last statement. Could somebody help me get the last one right?


TIA,
Babu

roamingnomad
08-06-2003, 05:40 AM
Please do not cross post.

babu_says
08-06-2003, 06:57 AM
The following worked

[...]$ echo ${var1%*/*}
xyz

Apologies for the cross post,
Babu

dchidelf
08-06-2003, 04:42 PM
${var%str}
attempts to remove the pattern matching string from the right of var.
there is no pattern matching */ at the right of your var1.
${var1#*/}
would remove the pattern matching */ from the left of var1.

${var%%str}
removes the longest matching pattern
and so does
${var##str}