Hacker News new | past | comments | ask | show | jobs | submit login
Unix didn't use to support '#!', a brief history (utcc.utoronto.ca)
87 points by zdw on July 16, 2022 | hide | past | favorite | 62 comments



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).

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/


If you want a simpler polyglot, here's a sh/bat to get you started:

  REM=;echo hello from sh;exit#
  echo hello from cmd


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 name for #! must have originated as hashbang which was abbreviated as ’shbang and then later gained an e to become shebang?


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".

So even under that original meaning it fits.


> 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.

https://www.etymonline.com/word/shebang


In many languages outside the anglosphere the word mouse relates uniquely to technology, as do bit, chip, trap, scan, monitor, file, mail, etc.


I always thought it was sharp bang = shabang


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).


Windows handles Unicode just fine. It’s just not UTF-8. The reason they used # is that it’s on the standard keyboard.

But hey, don’t let me get in the way of some ignorant Windows-bashing.


Where I'm from:

"#" => "hash" (never had I heard it being called "pound")

"!" => "exclamation mark/point" (never had I heard it being called "bang")

So to me "#!" was "hash exclamation" in my college in home-country.

Then I went to USA for an exchange program, where people consistently called it "she bang" and "pound bang". Took me a while to get it.


> "!" => "exclamation mark/point" (never had I heard it being called "bang")

Used in Unix-y circles since at least the 1980s, where "bang paths" were used for UUCP routing:

* https://en.wikipedia.org/wiki/UUCP#Mail_routing

* http://www.catb.org/jargon/html/B/bang-path.html


I first heard "bang" for "!" in the context of "interrobang" (‽).

Notably I seem to recall I first encountered it as the symbol found on the forehead of Barry Trotter, a parody Harry Potter published in 2001.


That one is my personal favorite.

Ref: https://www.merriam-webster.com/dictionary/interrobang


> never had I heard it being called "bang"

DuckDuckGo also calls exclamation points bangs https://duckduckgo.com/bang


The use in the unixy area was probably reinforced by UUCP "bang paths".


Hash is extremely contemporary, newer than number, and still a nickname. Pound is older, but it's true proper name is octothorpe.


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.


Or in Germany, it's sometimes called "Lattenzaun" (lattice fence)


Or even 'hash pling'.


Whenever I'm about to start a bash script, I have to say "shebang" in my head to remember which goes first: the "#" or the "!".


Doubt it. Hash was a pretty uncommon name for # until Twitter introduced hashtags.


In en-US, sure. But it was basically the only usage in en-GB, due to £.


Not really. Many people called # the crosshatch, hatch mark, or hash mark. Twitter was late to the game.


My favorite unix shebang related oddity:

    #!/usr/bin/env
    echo This might not do what you thought.


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.


> Unix has lots of weird cruft littering its dark corners

Indeed it does -- try logging in to your Linux machine with your username in all-caps :-)


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.


With all the shabang, shebang, splatping going on ... someone might stumble upon the magic word and turn into Captain Marvel.


Why isn't this in the file's metadata?


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)


Runs contrary to the unix philosophy.


Unix didn't used to support VIM


The Prophet Unix needed to come first to make the way ready for the Messiah Vim.


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?

[1] the other one was this video by youtuber Vsauce, https://www.youtube.com/watch?v=vjqt8T3tJIE

EDIT: wow so many interesting responses, thank you!


https://www.merriam-webster.com/words-at-play/is-it-used-to-...

This article says that in American English it’s considered an error, but it’s accepted in British English

I think that “used to” is the form seen so often that “use to” just looks and sounds weird to me. I would never use it


I'm American, and I'd also write "didn't used to". The hard 's' necessitates the 'd', otherwise it'd be pronounced "yooz"


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".

[0] https://ell.stackexchange.com/questions/100674/didnt-use-to-...


The M-W article says that "it appears to have won some measure of acceptance" in en_UK, and quotes the Daily Mail for an example...


I don’t think the Daily Mail is known for idiosyncratic grammatical style


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.


I suppose a clearer way to say this was "Unix didn't always support the shebang."


Off topic: why isn’t it “didn’t use”?


It is. "Didn't /used to/" is a mistake in American English, according to prescriptivists anyway:

https://www.merriam-webster.com/words-at-play/is-it-used-to-...


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.


But does ”never used to” really mean the same as ”didn’t use to”?

”Unix never used to support shebang” almost makes it seem like it just happened.


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 [...].


EDIT: Never mind, sorry, I missed part of the article, it does indeed say what you say.

---

That's the opposite of what your source says:

> In writing, however, use to in place of used to is an error.

Used to X was the standard past tense of to use in the sense of being in the habit of:

I used to fish: I was previously in the habit of fishing, correct both in the past and today.

I use to fish: I am presently in the habit of fishing, correct in the past but no longer understood today.

The second, however, is according to MW occasionally misused to mean "I was previously in the habit of fishing".


There's a difference when use is preceded by did:

> 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.


Either seem awkward to me, esp. when written, I'd prefer "didn't always support".


Classic HN. One comment about the article. Nine comments about the title.


Or nine comments about the scrollbar behavior or design of the content.



"used to" alone is correct in many situations, "didn't used to" is considered wrong by prescriptivists.

Including the "didn't" in the search shows that it's still close though: https://trends.google.com/trends/explore?date=all&geo=US&q=d...


For eunuchs it would be... never mind.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: