Skip to main content
added 133 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

The reason for using ${$0##*0##*/} is that it doesn't involve an external program call, but it is kind of obscuring what is going on.

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

The reason for using ${$0##*/} is that it doesn't involve an external program call, but it is kind of obscuring what is going on.

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

The reason for using ${0##*/} is that it doesn't involve an external program call, but it is kind of obscuring what is going on.

added 133 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

The reason for using ${$0##*/} is that it doesn't involve an external program call, but it is kind of obscuring what is going on.

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

The reason for using ${$0##*/} is that it doesn't involve an external program call, but it is kind of obscuring what is going on.

added 3 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo x=/a/b/c/d
d
$ basename $x
d
$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page: ${parameter##word} Remove matching prefix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the #'' case) or the longest matching pat‐ tern (the ##'' case) deleted.

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo x=/a/b/c/d
d
$ basename $x
d

From the man page: ${parameter##word} Remove matching prefix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the #'' case) or the longest matching pat‐ tern (the ##'' case) deleted.

This cuts of all the preceding path elements, just as basename $0 would do. The ## tries to find the longest matching expansion of the prefix pattern:

$ x=/a/b/c/d
$ echo ${x##*/}
d
$ basename $x
d

From the man page:

${parameter##word}
       Remove matching prefix pattern.  The word is expanded to produce
       a pattern just as in pathname expansion.  If the pattern matches
       the  beginning of the value of parameter, then the result of the
       expansion is the expanded value of parameter with  the  shortest
       matching  pattern  (the ``#'' case) or the longest matching pat‐
       tern (the ``##'' case) deleted.  
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228
Loading