Shell scripts in /bin?

homercles337

Diamond Member
Dec 29, 2004
6,340
3
71
Why do some people write shell scripts, strip their extension, and then stash them in the /bin directory? This is just maddening to me. Scripts should not be mingling with binaries, if they do, they should be forced to keep their extension. I suspect its some stupid historical convention that should have been done away with decades ago. So why does it persist? Serious question...
 

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
Why do some people write shell scripts, strip their extension, and then stash them in the /bin directory?

Because bin is broadly accepted to be "where executable things go". The various Linux distributions can't even agree on where programs should be installed by root, and you're unhappy that bin is not held to literally mean "binary"?

This is just maddening to me. Scripts should not be mingling with binaries, if they do, they should be forced to keep their extension.

Why? Serious question.

I suspect its some stupid historical convention that should have been done away with decades ago. So why does it persist? Serious question...

Because there's generally no reason for users to care about the language some executable was internally written in, and forcing them to type a file extension (auto-completion is fine on the shell but non-existent in scripts they write) is pointless and annoying. The script has (or should have, anyway) a shebang identifying the correct interpreter (and therefore file type) in the first line. Every modern Unix-y OS that I'm aware of has the file command or an equivalent.


I have coworkers who were somehow taught that bin literally meant "bin", like "bucket", and therefore use it for scripts, help files, Perl modules, and God knows what else. Now that can be maddening.
 

janas19

Platinum Member
Nov 10, 2011
2,313
1
0
Hey, can either one of you guys give me an example of a widely used and common shell script? I want to incorporate them more to my routine, but I don't want to be doing sth no one has heard of.
 

homercles337

Diamond Member
Dec 29, 2004
6,340
3
71
Because bin is broadly accepted to be "where executable things go". The various Linux distributions can't even agree on where programs should be installed by root, and you're unhappy that bin is not held to literally mean "binary"?

Now, imagine that instead of building an entire OS, you are building an application. An application that contains a "bin" directory. From the beginning it is up to you and you alone what goes in there. Do you put scripts in there? Or would you say add a /bin/scripts dir to your application? You know for organizational purposes. Now imagine that you are a developer on a big ass mess of an application. Now imagine you are not a developer but a user writing scripts against this big mess of an application. Now imagine its not just one application but 4 of them, that all seemed to do the same stupid shit. Now you are me. My life sucks right now.

Why? Serious question.

A script is human readable and editable, a binary is not. Without an extension the only way to tell this is by size, and sometimes thats borderline because i have seen scripts that are nearly 10k lines long. A bash script that is 10k lines long...

Because there's generally no reason for users to care about the language some executable was internally written in, and forcing them to type a file extension (auto-completion is fine on the shell but non-existent in scripts they write) is pointless and annoying. The script has (or should have, anyway) a shebang identifying the correct interpreter (and therefore file type) in the first line. Every modern Unix-y OS that I'm aware of has the file command or an equivalent.

Not having to type an extension? Thats the best you got? It seems to me that one could write a single script that would capture the command, sans extension, and the thing, no? What happens when you make an executable of your script? Well, it disappears from /bin/scripts and appears in /bin.

I have coworkers who were somehow taught that bin literally meant "bin", like "bucket", and therefore use it for scripts, help files, Perl modules, and God knows what else. Now that can be maddening.

Sure sounds like it. I should mention that i am not a software developer, or engineer, or conjurer, or whatever. I am a scientist who uses programming as a tool, who also made a very bad career choice/change 6 months ago.
 

janas19

Platinum Member
Nov 10, 2011
2,313
1
0
A script is human readable and editable, a binary is not. Without an extension the only way to tell this is by size, and sometimes thats borderline because i have seen scripts that are nearly 10k lines long. A bash script that is 10k lines long...

Not true. You can open a script/binary in a text editor. Inconvenient perhaps, but entirely possible.
 

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
A script is human readable and editable, a binary is not. Without an extension the only way to tell this is by size, and sometimes thats borderline because i have seen scripts that are nearly 10k lines long. A bash script that is 10k lines long...

Code:
$ file mymysteryfile

Not having to type an extension? Thats the best you got? It seems to me that one could write a single script that would capture the command, sans extension, and the thing, no?

Why jump through the extra hoops, and possibly break command auto-completion in the process (a major sin)? Anyway the problem is not typing it, but remembering it. And remembering that some of the commands you run require it, but others don't...

What happens when you make an executable of your script? Well, it disappears from /bin/scripts and appears in /bin.

1. Other than some pathological cases, if it's a script it is/should be executable.

2. Consider the case where I as a user do not have these locations in my path, and so have to actually provide the full path each time. Or have scripts that call the executable and, as a best practice, provide the full path. Now consider that you are breaking things for me, and in a way that will not be remotely obvious to me.

Sure sounds like it. I should mention that i am not a software developer, or engineer, or conjurer, or whatever. I am a scientist who uses programming as a tool, who also made a very bad career choice/change 6 months ago.

Where I work we would refer to this as an "opportunity to excel" :D
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
This is just maddening to me. Scripts should not be mingling with binaries, if they do, they should be forced to keep their extension.
Why? Serious question.
I didn't see a good answer to this question. After all, scripts and binaries are all executables. Scripts just happen to be easier to edit.

You mentioned 4 of something. Are you having trouble with multiple bin directories, like /usr/bin and /usr/local/bin? Do you know about the "which" and "locate" commands?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Why do some people write shell scripts, strip their extension, and then stash them in the /bin directory? This is just maddening to me. Scripts should not be mingling with binaries, if they do, they should be forced to keep their extension. I suspect its some stupid historical convention that should have been done away with decades ago. So why does it persist? Serious question...

Have you ever looked at how many scripts are in /bin and /usr/bin by default? I just looked on my Debian system and roughly have roughly 900 scripts (e.g. bash, perl, python, etc) in both of those directories combined. Those directories may have only contained binaries back when they were named, but that hasn't been the case for decades now.

I wouldn't my own, local scripts in either of those directories as they're meant to be managed by the system though. I tend to use ~/bin unless it needs to be available to everyone and then it would likely go in /usr/local/bin.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
I didn't see a good answer to this question. After all, scripts and binaries are all executables. Scripts just happen to be easier to edit.

You mentioned 4 of something. Are you having trouble with multiple bin directories, like /usr/bin and /usr/local/bin? Do you know about the "which" and "locate" commands?

I'm going to have to echo this.. What is the big issue? /bin has meant "files I want to execute" for a long time (It has been like that at least as long as I've been working with linux).


Homer, you ask the question "What about for organization?" And my answer is I would probably put the scripts in their own folders and then when make time comes around, I would copy them into the bin folder if they were meant to be executed by the user. I don't care if my bin folder has 100 different programs in it, I care that my source is well organized and that when the time comes to run, it is easy to do.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
Nothing we custom write goes into /bin or /usr/bin or even /usr/local/bin where I work. We instead use /opt/companyname/bin, /opt/companyname/lib and /opt/companyname/src for all of our custom work.

We do not differentiate between a script and a binary file. Both are executable. I only care who can execute it.