How much code in Linux?

In C

main(){}
1 Like

That’s what I thought too - sure the shortest program code would be in assembler - not a HLL

1 Like

But will it work without the ‘return 0’?

Why dont you test it?

2 Likes

Something like a JMP instruction to itself.
Would run forever but be short code.

2 Likes

Okay, will try…

We can cheat a little more: The exit builtin being not mandatory in shells, we can say the shortest program in bash (and other shells) is the empty program: $ bash -c "" is equivalent to $ bash -c exit.

For most interpreted/script languages, this rule is true (the end-of-program instruction/builtin is optional at the end of the script), and the same idea can be used:

  • PHP: $ php -r "" or $ php -r exit;
  • python: $ python -c "" or $ python -c exit
  • perl: $ perl -e "" or perl -e exit

So, the shortest program in bash/perl/python/etc. is… the empty string :slight_smile:

3 Likes