|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to get it's own file name within the same shell script?
Hello all,
This may be a silly question, but, let me ask... I searched the knowledge base, but couldn't get any help... My script creates a log file. I need to name log file as whatever the script name with a ".log" extension. Example: For the script name "start_cmd.sh", the log file should be named "start_cmd.sh.log" in the same script directory. How do I get the script file name within the shell script? Thanks. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
It should be in $0. (that is dollar zero)
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks for the help Perderabo.
|
|
#4
|
|||
|
|||
|
Belt and braces...
To be sure that you only get the script name, try using:
basename $0 Like so: LogFile="$(basename $0).log" This solves the issue of calling the script with a path name attached to the front. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell or perl script needed for ldif file to text file conversion | LinuxFriend | Shell Programming and Scripting | 1 | 04-23-2011 01:37 AM |
| Execute unix shell script to text file using the script | mastercar | Shell Programming and Scripting | 4 | 05-21-2010 05:32 AM |
| how to read dbf file in shell script and to convert dbf file usinf shell script | gauara | Shell Programming and Scripting | 6 | 05-12-2009 10:25 AM |
| (Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script | praka | Shell Programming and Scripting | 6 | 04-15-2009 06:09 AM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 04:25 AM |
|
|