# 50. bash, 1024 bytes

    #16  "(}23!@)" 3//v\D(@;'[af2.qc]GkGGZ'#)"14";n4
    #/*` "[!PPP(22)SP(>7 7*,;68*,@;'1,@ ␉␉␉␉ q
    #>␉
    # >36!@␉
    #`<`
    #<]+<[.>-]>[
    #{
    #z}
    #
    #=<xR+++++[D>+++++++L+++<-][pPLEASE,2<-#2DO,2SUB#1<-#52PLEASE,2SUB#2<-#32DOREADOUT,2DOGIVEUPDOiiipsddsdoh@O6O4/]>+.-- -. >][
    #Rx%>~~~+ +~*ttt*.x
    #D>xU/-<+++L
    #R+.----\).>]|
    #[#[/v/v(/0l0v01k1kx0l0ix0jor0h0h1d111x0eU0bx0b0o1d0b0e0e00m1d0i0fx0g0n0n11x0o0n0cx0c0o0f0c0gx0g0f0h0j0j0i0001k10vx0v0l111111^_)  0046(8+9+9+9+9+=!)
    ###|
    '\';echo 50;exit;';print((eval("1\x2f2")and(9)or(13))-(0and 4)^1<<(65)>>(62))or"'x"or'({({1})({1}[(0)])}{1}\{1})'#}#(prin 45)(bye)|/=1/24=x<$+@+-@@@@=>+<@@@=>+<?#d>+.--./
    __DATA__=1#"'x"//
    #.\."12"__*'
    ###;console.log 39
    """"#//
    =begin //
    #ssseemeePaeueewuuweeeeeeeeeeCisajjapppp/*/
    #define z sizeof'c'-1?"38":"37"
    #include<stdio.h>
    main(  )/*/
    #()`#`\'*/{puts(z );}/*'``
    <>{# }//
    #}
    disp 49#//
    #{
    1}<>//
    $'main'//
    #-3o4o#$$$
    #< >"3"O.
    =end #//
    """#"#//
    #}
    #|o51~nJ;#:p'34'\
    #ss8␛dggi2␛ `|1|6$//''25  =#print(17)#>27.say#]#print(47)#]#echo 21#ss*///nd^_^_Z222999"26

Want to learn more? Try the [polygot chat](http://chat.stackexchange.com/rooms/55553/polyglot-development)!

[Try them online!](https://tio.run/nexus/bash#zVpJc9tIlj43/kJd0iDLBEgCIKnFCwlasi3XqDZrLNkVYZKWQDBJwsJWWCRKMhVznYk59L0vc@z/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Gq3iLm7K1F8WOVmehKzRViQQtbPayyGokC8wmwBokgKu5tnNNvM6hAy/iNMFBfosdtRsGvo81AQX3kBvL2GWnHSxe42Xtf21mgSfS7akPG4wkmLLteUr2AuoYne1Yrd@CwDVDmAq/UalEPOPiIGUQltiqLM/Lcat/biS9IVMgoXVYjG/MsVcqWb1oK2Q2NW4rfygufoVXZXt6@DxY/dT3AsGbT2wM/qt1YL2XDnVPAlSzezANprtGMy2s16t5g3sQP9BiwXzgd0AMGgT5lS/Wlo6tAtzpXr9shca1@Gg/qYX1pqDel6vfrQv647dqM/whdrqfv1XKG@hSi2zL2th2@ngS7f2DU3Edlpz2jemaMup5tuXPWdgN/S2j4212hsIAz7Tnl@rDXQQ97F4d2Pbf/zYqfndWds3DJ2gPm28eNPLMBjUbHp/rjmd2YvLXo79zzX82iDj62Ae@27aAPjAXxs6luZbsS55nBF7M7AX2Hb144vqx6r96NFlb2YEg7pU//PGyvDE/IyYX/cRrfpx3bGESkQFr6nfes@/NaspU@vwPii5Hq/tlBxWP2IlXp2G@f8B "Polygot driver on TIO Nexus")

As usual, I replaced literal tabs with `␉` and literal ESC characters with `␛`, due to limitations of Stack Exchange. You can get an easily copiable version of the program from the "input" box of the TIO link above.

## Rundown

This program prints **50** in bash, **49** in Octave, **48** in Deadfish~, **47** in Lily, **46** in Cubix, **45** in PicoLisp, **44** in alphuck, **43** in reticular, **42** in evil, **41** in brainf\*\*\*, **40** in Minimal-2D, **39** in CoffeeScript, **38** in C, **37** in C++, **36** in Labyrinth, **35** in INTERCAL, **34** in Rail, **33** in Incident, **32** in Whirl, **31** in Modular SNUSP, **30** in Whitespace, **29** in Trigger, **28** in Brain-Flak, **27** in Perl 6, **26** in 05AB1E, **25** in Pip, **24** in Thutu, **23** in Hexagony, **22** in Underload, **21** in Nim, **20** in Prelude, **19** in Reng, **18** in Cardinal, **17** in Julia, **16** in Pyth, **15** in Haystack, **14** in Turtlèd, **13** in Ruby, **12** in Fission, **11** in Befunge-98, **10** in Befunge-93, **9** in Perl 5, **8** in Retina, **7** in Japt, **6** in SMBF, **5** in Python 2, **4** in ><>, **3** in Minkolang, **2** in V/Vim, and **1** in Python 3.

## Verification

Most of the languages are tested by the test driver above. The usual four culprits need testing separately:

* **Incident** was tested using its official interpreter, offline;

* **Deadfish~** was also tested using its official interpreter, offline;

* **Modular SNUSP** was tested online [here](http://www.quirkster.com/iano/snusp/snusp-js.html);

* **Reng** was tested online [here](https://jsfiddle.net/Conor_OBrien/avnLdwtq/).

## Explanation

I was looking at various leads for languages to add. One possibility was to find a language with `#` line comments that could plausibly be added to the "scripting language" line (which handles Perl, Python 2 and 3, and Ruby). It took me a while to think of an appropriate language that could be syntax-compatible with the ones already there, though.

It turns out that the answer had been staring me in the face for ages. If you click the TIO link above, it'll open up the polyglot test driver, which is written in bash. So all this time, I had a tab saying "Bash — TIO Nexus". You'd have thought that'd be a hint, but apparently I missed it. As a bonus, bash is also a scripting language, so the term "scripting language line" is still appropriate.

The bash program starts in the same place as the other scripting languages. However, there's a fairly simple way to split it away from them; in single-quoted strings, `\` is an escape character in most languages, but not in bash. So we can hide bash code from the other languages via `'\'…';`, which is a degenerate statement (with no effect) in Perl, Python, and Ruby, but executed in bash. `echo 50;exit` is a fairly simple way to end the bash program. Well, almost.

The biggest problem here is that bash will, upon running `exit`, continue parsing until the end of the current line (even though it doesn't execute the code in question), so we need to make sure there are no syntax errors on the rest of the line. We have a `'` just after `exit;` that isn't (and cannot be) immediately matched. Later on on the line, `'…'` is used to hide some Brain-Flak code from the scripting languages, but that would unhide it from bash. As a result, we need to change what sort of string literal we're using to hide the code, going from single-quoted to double-quoted strings. `or"'"` does the trick without disturbing Perl, Python, or Ruby (as the left-hand argument is truthy in every case).

We now have an unmatched double quote that extends onto a future line. It was fairly hard to close it without disturbing at least one other language; what we actually do is to change the way we hide code from bash from double quote back to an unmatched single quote in a Python/Ruby comment on the subsequent line, and finally close the single quote at the end of the line after that.

### Pyth and 05AB1E

Messing around with double quotes also disturbs the languages that were using double-quoted strings to hide code, Pyth and 05AB1E. The main trick we use here is to ensure that every double quote we add has another double quote soon afterwards in order to expose as little code as possible. (This explains the extra double quote on the `__DATA__` line, which isn't necessary for bash.) Pyth uses `\` as an escape character; the main upshot of this is that it limited the scope I had for messing around with strings in the scripting languages, forcing me to use the rather convoluted method above (as I couldn't easily make use of the difference in `\` behaviour between bash and everything else). In 05AB1E, `'` acts as an escape character *outside* strings, and having it escape the leading `"` wouldn't do. So I ended up needing to place a useless padding character (defaulting to my usual `x`; it makes things easier to read!) inside the `"'"` constructs that are used to change between bash quoting styles.

### Prelude

By far the hardest language to fix here. The problem is that the scripting line, with all its parentheses, was moved sideways, and thus the Prelude control flow (which cares a lot about the way in which parentheses are vertically aligned) was completely destroyed. I thus had to try to reconstruct something that works.

Worse, the current first line (which I really didn't want to rewrite) places something of a hard limit on where the parentheses can appear. It starts off with a nonzero digit (two of them, in fact!), and is soon followed by an opening parenthesis. That's a loop in Prelude, and loops early on in the control flow in Prelude cause a number of different issues (mostly because they cause more code to run, rather than less). As such, I badly needed to open a 0-iteration loop on some other line in order to skip over that code. The `main` line for the C program is highly suitable, but we need to be very careful with where the matching closing bracket is; too far right and the unmatched bracket on the `#R+` line will cause trouble, too far left and it won't comment out enough code. (Bear in mind that an opening parenthesis on one line can match a closing parenthesis o a different line.)

Once that's done, we have just enough space to stick in an opening parenthesis on the Incident line, and we've finally got safely past the first few characters of the program. However, the difference in parenthesis placements ends up meaning that some of the Incident/Whirl code actually runs in Prelude, corrupting the stack. Instead of trying to prevent this, I moved some of Whirl's zeroes further to the right, allowing them to give us a working Prelude program again.

One other small change was on the first line of the program; the final parenthesis of the line was in a position that was very hard to avoid. I added an extra `c` just after the Pyth code to shift it to the right. (Many languages are parsing that point of the program, so it took a surprising amount of trial and error to find a padding character that wouldn't break at least one language!)

### Incident

Prelude was hard enough by itself, but getting Prelude and Incident working at the same time was nightmarish. Prelude placed a lot of constraints on the code which prevented me freely moving things around, and thus made accidental token construction harder to golf out. For example, Prelude only really needs one `0` moved out to the right, but that caused `00` to become a failed token, breaking some of the tokens we wanted as part of the Incident program (because if two tokens overlap, they're both rejected, and the `00` was overlapping a token we wanted in addition to overlapping itself). I had to move both out to make a fourth copy and prevent it being even considered as a token.

More subtle are the tokens `;'` and `␠␠` (i.e. two space characters). The issue is that these both appear *before* the `kG` that is being used to jump to the start of the program, and thus will break Incident's control flow (in addition to breaking the program's centre point).

Removing a copy of `␠␠` by breaking it up doesn't seem viable. Removing it via overlapping it might be possible (`␠=` is a promising potential overlap), but it's almost certainly less verbose to just add a fourth copy, which is what I did here.

Meanwhile, we can use a different trick for `;'`. Breaking it up isn't something I wanted to try, given that it's used in fairly spacing-sensitive situations. However, it's not *that* near the start of the program (despite appearing on the first line), so it's plausible that we could jump over it (thus causing it to not affect control flow) rather than needing it to not exist. I looked for a suitable token to use for the jump which wouldn't screw up any of the other languages. `/v` appears a little earlier on the first line, and doesn't break anything, and thus that's what I used.

## 50 languages in a kilobyte of code

It was pointed out by @MistahFiggins that my 1025-byte submission would be way neater if it were 1024 bytes (especially as the fiftieth language is a milestone in its own right). This required finding a byte of savings somewhere. In this case, I saved three bytes in the Deadfish~, at the costs of two extra bytes used to make Incident tokens line up correctly, and thus bringing the program down to 1024 bytes exactly.

Previously, the formula that the Deadfish~ code used was (2²+2)²+10×1+2 = 48. The new formula is (3²-2)²-1, also producing 48. Surprisingly, it isn't that much shorter to write in Deadfish~, despite being considerably simpler.

This also gives us a ([VIP score](http://codegolf.stackexchange.com/questions/65641/the-versatile-integer-printer)) of .008192. Not only is this a new record, it's also a nicely round number in its own right (which is, obviously, a consequence of having nice round numbers as the inputs to the formula).