ugh. Sounds like an ugly snippet i used to write for something. I showed it
to someone, he frowned (or I imagine he did, I looked at his face through an
internet forum), and told me to just use basename instead.

cmd=`basename $0` is more understandable.

On Mon, Jun 2, 2008 at 8:15 PM, fooler mail <[EMAIL PROTECTED]> wrote:

> On 6/2/08, Ramil Galib <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > I saw in a script this line:
> >
> >          cmd=${0##*/}  # Command's basename
> >
> > Echoed the value of cmd and this returns -bash.
> >
> > I cant seem to figure out how this works.
>
> it is a "parameter expansion"... sub section of "expansion" section of
> bash man page in the syntax of:
>
> ${parameter##word}
>
> ${0} will return the name of a running program
>
> */ will find the last occurence "/" character and strip all the
> characters starting from the beginning upto the last occurence of "/"
> character...
>
> for example:
>
> #!/bin/bash
>
> cmd=${0##*/}
> echo $cmd
>
> save and name it to test.sh with execute permission...
>
> ${0}  will give you
> /path/be/it/absolute/or/relative/depends/on/how/you/run/test.sh
>
> ${0##*/} will strip
> "/path/be/it/absolute/or/relative/depends/on/how/you/run/" and give
> you the results of "test.sh" without the qoutes...
>
> fooler.
> _________________________________________________
> Philippine Linux Users' Group (PLUG) Mailing List
> http://lists.linux.org.ph/mailman/listinfo/plug
> Searchable Archives: http://archives.free.net.ph
>



-- 
thing.
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph

Reply via email to