![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find the geographical location within a shell script | eamani_sun | Shell Programming and Scripting | 1 | 05-13-2008 07:27 AM |
| script to check for a condition inside a file | kiran1112 | Shell Programming and Scripting | 11 | 03-21-2007 05:38 AM |
| excutable script to copy a file to a different location. | nazehcalil | UNIX for Dummies Questions & Answers | 4 | 12-21-2006 05:17 AM |
| running sed inside script file | bajaj111 | UNIX for Dummies Questions & Answers | 4 | 11-08-2006 02:58 AM |
| Creating a file inside a script | sendhilmani | Shell Programming and Scripting | 11 | 03-21-2006 04:24 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
how to find Script file location inside script
I have to find out the file system location of the script file inside script. for example a script "abc.sh" placed anywhere in the file system when executed shold tell by itself the location of it.
example #pwd / #./abc this is / #cd /root #./abc this is /root #cd / #/root/abc this is /root Last edited by asami; 03-14-2006 at 03:01 AM. |
| Forum Sponsor | ||
|
|
|
||||
|
Code:
[/tmp]$ cat pwd.ksh
#! /bin/ksh
self="${0#./}"
base="${self%/*}"
current=$(pwd)
if [ "$base" = "$self" ] ; then
{ cd "$current" ; echo $(pwd) ;}
else
{cd $current/$base ; echo $(pwd) ; }
fi ;
|
||||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|