0

I'm unable to understand what is the use of the following expansion in this code snippet:

image=$1
image_id=${image##*/}

I tried doing echo ${image##*/} for multiple values of image but I got the same results every time. Can this piece of code be removed?

$ image='var3-image'
$ echo ${image##*/}
var3-image
$ image=''
$ echo ${image##*/}

$ image='var3-image:asfd'
$ echo ${image##*/}
var3-image:asfd
$ image='var3-image#asfd**'
$ echo ${image##*/}
var3-image#asfd**
agc
  • 7,973
  • 2
  • 29
  • 50
vaibhavatul47
  • 2,766
  • 4
  • 29
  • 42
  • That's not a brace expansion; it's a parameter expansion. (Brace expansion refers to the expansion of something like `foo{1,2,3}` to `foo1 foo2 foo3`.) – chepner Jun 04 '19 at 15:05

1 Answers1

0

This removes leading / characters from the string.

$ image='/vra3-image`
$ echo ${image##*/}
vra3-image

From this link: ( http://tldp.org/LDP/abs/html/string-manipulation.html )

Substring Removal

${string#substring} Deletes shortest match of $substring from front of $string.

${string##substring} Deletes longest match of $substring from front of $string.

vaibhavatul47
  • 2,766
  • 4
  • 29
  • 42
  • 2
    No, it removes any prefix up through the last slash - in a common use case, any leading directory names. – tripleee Jun 04 '19 at 15:05