Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
The problem is that if you choose a decent name for your script, an upgrade might include something with the same name, which will either overwrite your command or at best cause confusion.
I suggest that you put your home grown scripts in your own directory structure: /usr/mystuff/bin or whatever, and further that you NEVER assume that it is in $PATH in calling scripts, but rather call it explicitly: /usr/mystuff/bin/whatever. This prevents the theft of "whatever" by another set of programs, and if some person upgrades the server years from now when you are long gone, and does not notice /usr/mystuff/bin, the calling scripts failure will immediately point them to the remedy. It's fine to have your special place in $PATH; just be sure to be explicit in any other scripts you write.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
The arguments of not putting scripts is /usr/local/bin are valid. Good that people think about it and write it down.
However, even with putting the scripts in another directory anywhere else but in /home/yourname/.... immediately put you in the backup problem anyway. But putting the scripts somewhere below the home directory causes a problem to make them available system-wide.
So far I have been putting my scripts in /usr/local/bin/<projectname> and call them by the full path. But whenever I migrate the system to new hardware I usually miss some of these files. That might have to do with my policy to upgrade servers. I hardly ever upgrade a running production server. I rather do a new install, configure the applications, move the data, bring the old server down and bring the new server up. But it wouldn't be the first time that I forget some files in the /usr/local/bin tree and notice that days afterwards when cron jobs fail or something.
What I also tried for one project (which has a web based user interface) is to put all files related to the project in the /var/www/<project> tree. I consider /var/www volatile, but I have the complete tree on my development system (and subsequently in SVN). This tree includes all scripts, php, tcl, bash, awk etc. Althought the files are used by the project, they can freely be called from anywhere as they are world readable and executable. I must say that this is the best solution so far, but it is not really suitable for single scripts not belonging to a project.
What I have been thinking about also is to put scripts in a designated directory in the file server all my Linux machines connect to. My file server gets backed up, whereas my client machines are not. This directory is not /usr/bin/local/... something for the abovementioned reasons, but somewhere in the user data tree. That path is not included in the $PATH, but why should it? Calling it by the full path name is not difficult if you have file name completion with <tab> and when the command is often used you find it in the history buffer anyway.
Truely the shell's parsing and substitution order takes a lot of mastering (I figure I forget it faster than I learn it!)
You are preaching to the choir :-)
Not only do I forget it, but I don't trust anything I remember. I work on so many different operating systems, with so many different shells - and of course there are some major differences between different version levels of even plain old Bash.
I'm very apt to use Bash test operators wrong because I've been doing a lot of Perl recently and vice-versa. I find myself more and more often second-guessing myself: does it really work that way? I better build a test harness and throw some data at it (not that doing that is a bad idea, but I find myself doing it for the simplest and silliest things!)
I therefore tend toward simple and old. People will look at stuff Iwrote and say "Well, you could have...". Yeah, I know, I *could* have. But I couldn't remember if that would work in old Bash or sh on an old Unix box, so I didn't. I wrote it dumb and stupid so it would probably work anywhere.
Calling it by the full path name is not difficult if you have file name completion with <tab> and when the command is often used you find it in the history buffer anyway.
jlinkels
It's the first time I find about this <tab> thing.. whoowaa..
Thanks for the info..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.