Format your code to make it more readable

  • Formatted code is easier to read. When writing or pasting code, surround it with three backticks before and after so that the forum formats it accordingly.

    Example of code which is not formatted and not readable:

    for ((i=0; i<{#inFiles[@]}; i+=perGr)); do printf '%s' "Making file {inFiles[@]:i:perGr} great again."
    done

    Surround it by three backticks before and after, like this:

      ```
      for ((i=0; i<${#inFiles[@]}; i+=perGr)); do
          printf '%s' "Making file ${inFiles[@]:i:perGr} great again."
      done
      ```
    

    Then the forum will show it like this - clear and legible:

    for ((i=0; i<${#inFiles[@]}; i+=perGr)); do
        printf '%s' "Making file ${inFiles[@]:i:perGr} great again."
    done
    
  • You can do the same for one or more words in a single line, by surrounding the word(s) with a single backtick before and after. Do this whenever mentioning code or filenames.

    Example of unformatted inline code:

    Every time I write echo ${foo} I smell cheese.

    Surround the code words with a single backtick before and after like this:

    Every time I write `echo ${foo}` I smell cheese.

    Then the forum makes the code part clear:

    Every time I write echo ${foo} I smell cheese.

5 Likes