Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto use script nam ( itself ) as a variable within script ?

Status
Not open for further replies.

bolobaboo

MIS
Aug 4, 2008
120
US
I have script call full_brwsgrsb_bkp.sh. I want to use its part of name "brwsgrsb" within script.
Any help would appreciate ?
 

Try this:
Code:
script_name=`basename $0`
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

Or, if your script has arguments, then try this:
Code:
scr_nm=`echo $0|cut -d' ' -f1 |xargs basename`
[noevil]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

Also, the above commands would give you the whole name of the script "full_brwsgrsb_bkp.sh", if you need the "pieces", just do this:
Code:
scr_nm=`echo $scr_nm|cut -d'_' -f2`
[medal]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top