FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

unix script directory

 


kv
I have a unix shell script run.sh. This works fine as long as I run it from the directory which contains the script. If I run it from other directories, it does not work (It uses some files in the script directory). Is there a way to get the directory in which script exists and change to it?
Antoine_935
Put this at the beginning of your script:
Code:
cd `dirname $0`

It gets the directory path of your script
If user types this
Code:
./shellscripts/script.sh

it will change dir to ./shellscripts


EDIT: I forgot the 'c' of cd Wink
kv
That worked. Thanks.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.