Following one example of the book << Learning the Bash Shell >> (O'Reilly),

echo ${pathname##/*/}
echo ${pathname#/*/}

The expected result should be, since ## remove the longest prefix which matches the patter /*/.

However, when I put these three lines inside a script file and run it inside bash, there is no result displayed. But type in these two lines one by one works and shows the expected result.

I wonder if there is any setting related to usage of this operator ## inside executable script.

(Using ubuntu\trusty64 within vagrant.)



The code works fine, the other part of the code affects the results.

In Addition

${path##*/} is a better choice as equivalent to basename command.

1 Answers

RavinderSingh13 On

Though echo ${pathname##/*/} works fine for me but IMHO you should try following.

echo ${pathname##*/}

Which means you are saying bash with help of regex to remove/substitute everything from starting till last occurrence of / with NULL.