Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!!
Spell out your words, and quit using that text-speak garbage.
This very much sounds like a homework question...what have you done/tried so far? This:
Code:
OWNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
...will mostly work. I'll leave it to you to figure out how to see if you're referencing a symlink or not, if it matters.
Spell out your words, and quit using that text-speak garbage.
Was that in the forum's how to ask a question page? I think i read it and followed that procedure before posting a question!!
And i read some where there, asking users to be polite!!!
Quote:
Originally Posted by TB0ne
This very much sounds like a homework question...what have you done/tried so far?
its not a home work stuff.
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:
Originally Posted by TB0ne
This:
Code:
OWNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
...will mostly work. I'll leave it to you to figure out how to see if you're referencing a symlink or not, if it matters.
So basically u are asking me to cut from $0 and do an internal cd and get pwd??
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!!
Was that in the forum's how to ask a question page? I think i read it and followed that procedure before posting a question!!
And i read some where there, asking users to be polite!!!
Think what you like, but posting text-speak isn't nice for ANYONE. And if you don't like the answers, you should first consider what you did to have someone reply like that to you. Did you look around the forum, and see how others respond to text-speak? Or do you think you can just do whatever you'd like, and everyone else has to be nice to you about it??
Quote:
its not a home work stuff. 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..
So basically u are asking me to cut from $0 and do an internal cd and get pwd?? 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...
I also asked you to spell out your words...yet you continue to use text-speak. If you can't be bothered typing out a word, why should anyone here be bothered answering?
And if you read the man page on the "cd" command, you'll see a way to handle symbolic links.
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.
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.
Sorry, but this has ZERO to do with native/non-native English speaking persons. The word "you" is spelled the same, no matter if English is your first or fifth language. And "coz", "wr", and "wat" are good examples too. Grammatical errors are one thing...using text-speak is another.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.