LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ${0##*/} (https://www.linuxquestions.org/questions/linux-newbie-8/%24%7B0-%2A-%7D-4175495387/)

anandg111 02-18-2014 10:50 AM

${0##*/}
 
base=${0##*/}

can someone please explain this ?

grail 02-18-2014 11:00 AM

Where did you get it from? To be honest, unless called in a script it is quite meaningless.

You may also like to read http://www.catb.org/~esr/faqs/smart-questions.html, as your current effort leaves little to be desired.

custangro 02-18-2014 11:04 AM

Same effect as

Code:

$(basename $0)
You're trimming everything to the left using '/' as a delimiter.

--C

anomie 02-18-2014 04:43 PM

anandg111, see the bash(1) manpages, under the "Parameter Expansion" section. There are a number of interesting features here, none of which require firing off a child process.

Some of my favorites:
Code:

[texas] ~> _line='Stay warm'

[texas] ~> echo "The length of \$_line is ${#_line}"
The length of $_line is 9

[texas] ~> echo "The first six characters from \$_line are ${_line:0:6}"
The first six characters from $_line are Stay w

[texas] ~> echo "Replacing (warm) with (happy) gives us: ${_line/warm/happy}"
Replacing (warm) with (happy) gives us: Stay happy

[texas] ~> echo "Greedily stripping prefix up to (a) results in: ${_line##*a}"
Greedily stripping prefix up to (a) results in: rm

[texas] ~> echo "Greedily stripping suffix up to (a) results in: ${_line%%a*}"
Greedily stripping suffix up to (a) results in: St

Anyway - read the manpages.

chrism01 02-19-2014 05:19 AM

A really good page on Parameter Expansions & related tricks http://wiki.bash-hackers.org/syntax/pe


All times are GMT -5. The time now is 09:55 PM.