get shell scripts own directory name
Hi,
I want to get a shell scripts own directory name... pwd might not help here, coz that script can be executed from any wr else as well... i can cut it from $0 but this will go wrong if that script is executed from inside that directory.. so wats the easiest way to find that scripts own directory name?? Thanks in advance!! |
Quote:
This very much sounds like a homework question...what have you done/tried so far? This: Code:
OWNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
Not always possible. More here.
|
Quote:
And i read some where there, asking users to be polite!!! Quote:
i was doing if [`dirname $0` not equals "." ] then dirname $0 ;else pwd; but i came up with a testcase of */Actual_dir/subdir/../test.sh , so my code fails here.. Quote:
This satisfies that test case. good on that. if some one creates a symbolic link of this executable and executes it using that symbolic link, is that what u asked? i think i will use if [ -z `readlink $0` ] then $0 else readlink $0, something like that... Somehow i dont feel better in doing this with $0, i don believe on that $0's value.. Anyways this has solved my prob as of now... Thanks!! |
Quote:
Quote:
And if you read the man page on the "cd" command, you'll see a way to handle symbolic links. |
http://www.linuxquestions.org/questi...mmands-852230/
In this thread also, we can see evidence of not understanding that "non native English speaking persons" don't know what's correct "speak" and what's not. (Apart from - at times - incorrect technical advice). I think that native English speakers (not all mind you) should be just a little more understanding of others. You see, these others may not be aware that they are writing text-speak-garbage. Sure, we non native English speaking persons will try to improve. OK |
Quote:
|
All times are GMT -5. The time now is 05:55 AM. |