r/ProgrammerHumor • • Nov 06 '20

Meme Totally agree

Post image
52.1k Upvotes

474 comments sorted by

View all comments

235

u/_letMeSpeak_ Nov 06 '20
#!/usr/bin/python3

111

u/justinf210 Nov 06 '20 edited Nov 07 '20

Doesn't bash read that though, not python? Or am I thinking of something else?

Edit: Huh, Cunningham's Law.

43

u/timurhasan Nov 06 '20

almost correct, the shebang is read by the program loader.

110

u/tndaris Nov 06 '20

60

u/GRAIN_DIV_20 Nov 07 '20

I hardly know her

9

u/iamacuteporcupine Nov 07 '20

We need gender equality!!!

Proceeds to make a language with hebangs !

2

u/DasSkelett Nov 07 '20

It's not a language feature, it's a kernel feature. You'll need to create a new kernel to do that (or get your code into an existing kernel, good luck).

2

u/iamacuteporcupine Nov 07 '20

Basically bash, if I am not wrong, is it?

4

u/DasSkelett Nov 07 '20

No, Bash is not a kernel. Bash is a shell, a userspace software.

You'd need to get your code into Linux, Windows, XNU (macOS), or the BSDs.

Bash and other shells ignore shebangs because they start with a #, which, just like Python, denotes a comment.

Only when you ask the kernel to execute a script file, it'll see the #! that shebangs start with, read the path afterwards, then launch the program at that path and pass it the script location as parameter.

3

u/iamacuteporcupine Nov 07 '20

Okay, understood now.

3

u/jaerie Nov 07 '20

I bang

You bang

He bang

Shebang

2

u/PM-ME-YOUR-HANDBRA Nov 07 '20

William Hung Intensifies

30

u/ericonr Nov 06 '20

It's actually the kernel :p

26

u/moochacho1418 Nov 07 '20

You’re a kernel

2

u/oezingle Nov 06 '20 edited Nov 06 '20

Doesn’t GNU bash read that for the kernel?

Edit:

The loader executes the specified interpreter program, passing to it as an argument the path that was initially used when attempting to run the script, so that the program may use the file as input data.

  • Wikipedia

So it does, because the loader runs through bash

15

u/ericonr Nov 07 '20

No it doesn't.

There are shells other than bash, and a program can directly use the execve(2) syscall on a file with a shebang without having to implement any sort of special parsing.

If you click the loader ( https://en.wikipedia.org/wiki/Loader_(computing) ) link in the quote you posted (without providing a link), you will see that the program loader is the handler for the execve system call, which means it's not something implemented in application code, but rather part of the syscall logic, which most of the time is implemented in the kernel.

5

u/x_interloper Nov 07 '20

Technically at binfmt_misc in Linux kernel. On a few OSes it's emulated at exec.

4

u/silentphoenix42 Nov 07 '20

The old Ricky Martin, shebangs man

1

u/DasSkelett Nov 07 '20 edited Nov 07 '20

Basj doesn't read it either, because Bash also uses # for comments (just like every other shell). The kernel does.

25

u/teagonia Nov 06 '20

#!/usr/bin/env python3

4

u/army_of_sloths Nov 07 '20

conda gang unite