3

Let's look at a simple code example written in Bash:

enter image description here

As you can see, the light grey comment highlighting in line 3 starts at the # symbol, although it's part of the reserved variable name $# and should not start a comment here.

Can this behaviour please be fixed? Thanks!

7

As explained in this meta.se FAQ post:

Stack Exchange does not have its own syntax highlighting engine. It uses Google Code Prettify. Therefore, any bugs and feature requests regarding syntax highlighting cannot be handled by Stack Exchange and should be directed to the team behind Google Code Prettify. In fact, as pointed out by the OP, there is already an open issue about this.

So, unless the SE folks want to get actively involved in the code-prettify project, I doubt they will fix it. The good news is that this is an open source project hosted on github so anyone else who wants to could give it a go and fix it.

Note that in the example you show above, you can get it to work as expected if you quote your variables correctly. Yet another reason to always quote your variables in shell scripts:

enter image description here

  • Yes, in that example quotes would be stronger than the comment #. But in another example, there should be no quoting: if [ $# -gt 2 ] was e.g. used here. But thanks for the answer! – Byte Commander Dec 2 '15 at 12:16
  • Oh, there's already an open issue on GitHub about this from April 22, 2015. You may want to edit that in... – Byte Commander Dec 2 '15 at 12:21
  • 3
    @ByteCommander if [ "$#" -gt 2 ] works perfectly well and is better practice. Even when not absolutely necessary, quoting your variables is a good habit to get into. The rule of thumb is to quote unless you need them unquoted. I fixed it in the post you linked to. – terdon Dec 2 '15 at 12:31
  • Oh, really? I guess I just learned something! ^_^ Thanks. – Byte Commander Dec 2 '15 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .