What is the meaning of ## in UNIX shell script?

Hi All,

I am new to unix shell scripting and I was documenting one of the unix script and encountered below statements -

for ii in `ls -1rt /oracle/admin/MARSCOPY/ext_files/fpm-ifpm/*.small.txt | tail -1 | awk '{print $1}'`
do
smallssim=${ii##/oracle/admin/MARSCOPY/ext_files/fpm-ifpm/}
prefix=`echo $smallssim | awk -F. '{print $1}'`

I tried to find the meaning of ## on google or other posts but could not find it.

Can anyone please help me understand meaning of the value smallssim?

Thanks in Advance.
Jay Shukla

Hello shuklajayb4,

Welcome to forums, hope you will enjoy learning here. It is called Parameter expansion, when you do a man bash you could see the following.

Here is an example of same too.
So let's say we have following string into a variable.

MYSTRING="Be liberal in what you accept, and conservative in what you send"

So here is the use of # and ## .

${MYSTRING#* }	Be liberal in what you accept, and conservative in what you send
${MYSTRING##* }	Be liberal in what you accept, and conservative in what you send

As you could see above(selected text will not be shown) # is removing the text till very first space and on other hand ## is printing the text till very last(maximum) match of space. I hope this helps you.

Thanks,
R. Singh

2 Likes

Thanks Ravinder !! This helps to understand it better.