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?
unix script directory
Put this at the beginning of your script:
It gets the directory path of your script
If user types this
it will change dir to ./shellscripts
EDIT: I forgot the 'c' of cd
| 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
That worked. Thanks.
