Justine Tunney's APE (actually portable executables) exploits, er, makes use of, the fact that a shebang isn't required to run a shell script.
The single executable file generated by the Cosmopolitan linker creates an insane polyglot binary executable that runs on 6 operating systems as well as on bare metal (i.e. bootable as its own OS); in addition, it's a valid Zip archive, and you can modify files inside it using any zip utility... fascinating stuff. On Linux, it bootstraps execution initially as a shell script, but the shell script writes the "ELF" file header and executes it (I'm probably doing a horrible job of explaining though).
If you're interested in learning more, this talk from 2021 is fascinating: https://www.youtube.com/watch?v=1ZTRb-2DZGs. It covers Redbean, a portable, run-anywhere web server built with the APE toolchain; since then Redbean 2 has been released, which adds a lot more features. Here's a link to Redbean: https://redbean.dev/
This reminds me of a bug in macOS that for a while caused our builds to fail once or twice a month with something like "/bin/sh: /bin/sh: cannot execute binary file"
This was because sometimes, the kernel would fail to execute a binary for some reason (this was the core bug), returning ENOEXEC to the libc, which, dutifully, would pass it on to the shell as documented in the article. Of course since the failed executable was a real binary, not a script, the shell would fail with the above error.
I haven't encountered the bug in a couple years, so I guess they finally fixed it. Silently.
the word "shebang" was a common word in the middle of the last century, so with exclamation point being bang, and i think more likely, shell starting with "sh", it was undoubtedly straight up selected because of the match to the word. "If you put a script in a file and start it with a hash and make it executable, /bin/sh will run the whole shebang for you" would be an accurate use of the word shebang. A similar bit of slang would be "/bin/sh will run the whole shootin' match for you"
>the word "shebang" was a common word in the middle of the last century,
taking just that part of the sentence out of context, that almost reads like some historical tome or some fantasy novel. or maybe it's that i lived a good chunk of the middle of last century and this kind of thing makes realize i've been doing this a lot longer than i'd like to admit
Actually taking that part out of context reminded me that "shebang" is a word outside of technology. It means something like "everything involved", the phrase I'm remembering is "the whole shebang".
> shebang (n.) - 1862, "hut, shed, shelter," popularized among soldiers in the U.S. Civil War, but like other Civil War slang (such as skedaddle) of uncertain origin.
> Perhaps an alteration of shebeen (q.v.), but shebang in the sense "tavern," a seemingly necessary transitional sense, is not attested before 1878 and shebeen seems to have been not much used in the U.S. Bartlett's 1877 edition describes it as "A strange word that had its origin during the late civil war. It is applied alike to a room, a shop, or a hut, a tent, a cabin; an engine house."
> Phrase the whole shebang first recorded 1869, but relation to the earlier use of the word is obscure. Either or both senses also might be mangled pronunciations of French char-à-banc, a bus-like wagon with many seats.
Sharp's a different thing, ♯ against #, it always amuses me that Microsoft's version of Java should be called C♯ when their OS has such dreadful support for Unicode that it's almost universally written C#, so C-hash (or C-pound for you left-ponders).
Outside of North America, hash has been the standard term for many decades; in that time period, the name pound was rarely used for it outside of the US. Number sign was adopted in international standards as a neutral compromise between US and UK usage; apparently, it is/was also the standard term in Canada, and saw regional usage in some northern parts of the US. I wonder whether the derived term hashtag is causing hash to make inroads into US usage?
Octothorpe has never been its “proper” name in any country; just a jocular nickname originating in the US telco industry, which spread from there to computing.
> Octothorpe has never been its “proper” name in any country; just a jocular nickname originating in the US telco industry, which spread from there to computing.
Octothope was coined by Bell Labs. It is certainly not jocular (what?). In point of fact, it is that symbol's proper name and how it is referred to in all Bell manuals and documentation, and this word coinage is little to no different to how the British began using # for pound to distinguish it from £, the currency.
Even though "hash," by hundreds of years, predates all other names for the symbol (originally, "hatch," marks one would make with a hatchet), hashing, the mathematical practice since the 1940's of transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string, was not married in identity or meaning or abbreviation to the # symbol by convention until probably 1990, regardless of location on the planet or country not in North America. No one anywhere in the universe was using the hash symbol in, say, 1975, to refer to the mathematical hashing in computer science. In 1975, the # was the octothrope properly and most commonly (even if no one used that term, they all had a telephone and they still do, and every telephone today still has an octothorpe button, i.e. not a hash button), or the number sign or the pound sign by popularity.
# was never used as an abbreviation for mathematical hashing, again, until maybe late 1980's, probably like about 1991 # became conventionally used by programmers, computer scientists and mathematicians to mean mathematical hash. And even today, every county in the world that has telephones properly has an octothorpe key, not a hash or pound key. Bell coined the term and established it's usage long, long before # was used for math hashes, and even to this day, the octothorpe symbol is likely more common than the hash symbol, just because there are so many damn phones.
Unix has lots of weird cruft littering its dark corners; for instance you can use : instead of #! and, if I remember correctly, the OS will use "the default shell".
Similarly, you can have your shell in the GECOS field be null, and again, you'll get the default shell. I think I had a bug report in with Sun complaining that XDM or the fancy XDM replacement didn't work correctly with a null shell value. Or maybe it didn't work if you had the character "ctl-l" as your password.
It's been a while. In any case, don't do these things.
> for instance you can use : instead of #! and, if I remember correctly, the OS will use "the default shell"
when I learned unix around 1980, you had to start a shell script file with a single # on a line by itself, and there was no bang option... but I want to say there was a way to select sh vs csh, though I can't recall it... maybe you had to start with a couple lines of Bourneshell, and that part would relauch csh on the same file. can't remember though. A dozen years later that was a common technique to launch perl scripts tho I don't recall why.
> Unix has lots of weird cruft littering its dark corners; for instance you can use : instead of #! and, if I remember correctly, the OS will use "the default shell".
I mean, it's basically what the article says. Anything that's not an executable and doesn't start with "#!" gets passed to the default shell. ":" is no exception here.
That does have a specific reason, it's not an arbitrary old thing. It's to support terminals that don't do lowercase. Like some old terminals such as Dec VT05 or TTYs (the ones that printed on paper often didn't support this or they had a mode-switch character for it rather than separate characters)
Old as it is, I'm sure these are still around in some production environments.
Because Unix's file metadata was traditionally very simplistic – and while many contemporary Unix-like systems do better–such as with extended attributes (xattrs)–that feature came historically late enough that it has never seen anywhere near as much use as it would have had it been implemented earlier.
I think the designers of Unix were (in part) reacting to some systems they'd experienced (such as IBM mainframes) which had very rich–yet complex, cumbersome and rigid–file metadata, and in reaction decided to make file metadata as simple as possible. The idea that you could support richness with simplicity (extended attributes as arbitrary name-value pairs, leaving the name and value format mostly up to applications) didn't seem to emerge until much later. I could be wrong about this, but I think contemporary Unix-like systems actually borrowed the idea from OS/2 (which in turn was possibly somewhat influenced by classic Mac OS resource forks)
Non native speaker here, it's the second time this week[1] that I see "didn't used to..." instead of what I believe to be the correct form "didn't use to...".
Aren't verbs after "did/didn't" always supposed to be in the present tense? For example you would say "I didn't see you last night" rather than "I didn't saw you last night". Is there a grammatical rule I'm missing?
Over at the English Language Learners [0] Stackexchange, reading through the answers and how they describe their references (I didn't click through to read those references), it seems like "didn't used to" is more acceptable in general for both American and British English, even though it shouldn't be correct because it breaks the rules.
I like this last part of one of the answers in particular:
> One of the strongest arguments against treating used to as a standard verb form is the pronunciation. According to the Cambridge Dictionary, with the verb form of use, the s is voiced /juːz/ whereas in the noun form it is not voiced /juːs/. In I used to and I didn't used to, the s is unvoiced. It's definitely not a noun, but it is also not a standard verb form: it is something unique, and that's what upsets the grammarians.
Aside, like sibling comment, I'm also a native American English speaker and it's always been "didn't used to".
I'm also a non-native English speaker, I also found the the title of the linked article weird and also saw the title of the Vsauce video recently. This all made me confused and I'm happy that you brought it up here and that people chime in to clear the situation up.
As a native UK speaker, for me it has always been "used to" and "didn't use to", although up to this moment I have never noticed the subtle difference.
Garner’s Modern English Usage (4th edition) acknowledges didn’t used to as “fully accepted” (Stage 5) and notes that it was almost twice as common in journalistic usage.
There’s long been open debate among linguists about what might be formally more correct, but with sound arguments on both sides. It mostly comes down to grammatical rule vs idiomatic phrase with a strong validating history.
That said, he suggests never used to as a way to escape the grammar debate while still keeping used.
Yeah, it's different: "Didn't use(d) to [...]" means that there was a time where it did not [...]; whereas "Never used to" means that at every previous time it did not [...].
> The problem becomes a little trickier in constructions with did. The form considered correct following did, at least in American English, is use to. Just as we say "Did he want to?" instead of "Did he wanted to?," so we say "Did he use to?" instead of "Did he used to?" Here again, only in writing does the difference become an issue.
> While in American English "did used to" is considered an error...
Personally, didn't used to looks jarring, but it made me open the article so…
Oh, excuse me, I entirely missed that section of the page. Makes sense there's a geographical distinction, I'm not American so I suppose I don't have the intuitive issue with it, but on reading I see the logic.
The single executable file generated by the Cosmopolitan linker creates an insane polyglot binary executable that runs on 6 operating systems as well as on bare metal (i.e. bootable as its own OS); in addition, it's a valid Zip archive, and you can modify files inside it using any zip utility... fascinating stuff. On Linux, it bootstraps execution initially as a shell script, but the shell script writes the "ELF" file header and executes it (I'm probably doing a horrible job of explaining though).
https://justine.lol/ape.html
If you're interested in learning more, this talk from 2021 is fascinating: https://www.youtube.com/watch?v=1ZTRb-2DZGs. It covers Redbean, a portable, run-anywhere web server built with the APE toolchain; since then Redbean 2 has been released, which adds a lot more features. Here's a link to Redbean: https://redbean.dev/