How can I determine the path of a shell script that I'm running right now ?
ok, I'm in:
/usr1/boor/home/ and I'm running: /usr1/Asher/home/scripts/main.sh I need for main.sh to know the path it is running in - no matter from where I'm running it. the $0 is the closest I got so far, the only problem is $0 also contains the name of the file itself ("main.sh") and I only want the path ("/usr1/Asher/home/scripts/") any ideas ? oh and I would rather not use the "cd" command in the script because it is needed to be in the same place later in the script. thanks |
Hi,
It's not clear to me what you actually want to do, but the following hopefully helps: dirname $0 => return the directory part. |
Try this in your script
Quote:
$PWD=`pwd` |
did you read bash's man?
did you try echo $_ ? |
Quote:
|
Quote:
it gives me the path of which i'm running script from (/usr1/boor/home/), not the path of main.sh |
Quote:
|
Quote:
this works: Code:
$(dirname $0) |
All times are GMT -5. The time now is 07:28 PM. |