![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| 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 10:27 AM |
| script to check for a condition inside a file | kiran1112 | Shell Programming and Scripting | 11 | 03-21-2007 09:38 AM |
| excutable script to copy a file to a different location. | nazehcalil | UNIX for Dummies Questions & Answers | 4 | 12-21-2006 09:17 AM |
| running sed inside script file | bajaj111 | UNIX for Dummies Questions & Answers | 4 | 11-08-2006 06:58 AM |
| Creating a file inside a script | sendhilmani | Shell Programming and Scripting | 11 | 03-21-2006 08:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 07:01 AM.. |
|
|||||
|
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 ;
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|