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