FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
script backup database
Full directory path
Perl Script - Internal Error 404 File not found
.sql problem
formularios y correo-e, !ayuda¡
a challenge?
Article Directory Script
free 10 Web Script Directory
Which is the best PHP Directory Script?
Directory Script
Directory Script for Free
What do you expect from a link directory script
Cannot create file
Arfooo directory script
Reply to topic    Frihost Forum Index -> Scripting -> Others

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