LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell:about $0 (https://www.linuxquestions.org/questions/linux-newbie-8/shell-about-%240-611293/)

lirong 01-05-2008 05:12 AM

shell:about $0
 
I know $0 means shell script name ,but how to just show script itself,not /xxx/.../scriptname. Thanks in advance
:)

colucix 01-05-2008 05:13 AM

Code:

basename $0
See man basename for details.

Edit: without invoking an external command, you can also do
Code:

echo "${0##*/}"
this remove from $0 the longest part of the pattern */ (any sequence of characters followed by a slash) from the beginning of the string.

lirong 01-05-2008 05:25 AM

Quote:

Originally Posted by colucix (Post 3012143)
Code:

basename $0
See man basename for details.

:) Thank you!

colucix 01-05-2008 05:39 AM

You're welcome! :) I edited my post before seeing your reply... I posted a little add-on.


All times are GMT -5. The time now is 07:59 PM.