ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I think I am in BASH, I am in the /etc/profile.local that I created, but I did not put #!/bin/bash at the top, so who knows what it is.
Anyway, I want to export PATH with an appended dir in there. Problem is, I need to know if it is already appended, because it gets appended twice. So how would I do this? I have tried "expr index...", grep wants a file, must be a way. If someone could please post the actual code instead of speaking in vague abstractions, that would be great. A coworker gave me a huge example script involving large functions and arrays and a main, but isn't there an easy way.
Anyway, I want to export PATH with an appended dir in there. Problem is, I need to know if it is already appended, because it gets appended twice. So how would I do this?
It should be quite possible to prevent a directory from being include in $PATH more than once without some sort of special construct. Just read the man page about bash how it read its profile and rc files. Then just don't include some directory twice in $PATH.
I read the man pages. It seems to indicate the etc/profile (which invokes etc/profile.local) would be the place for this. When I remove it from there I get no such dir in the PATH, when I put it in without your snippet, I get two after system startup and root login.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.