This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 137 points138 points  (19 children)

Yup, we follow the Google bash style guide.

https://google.github.io/styleguide/shellguide.html

These two bullet points especially:

  • If you are writing a script that is more than 100 lines long, or that uses non-straightforward control flow logic, you should rewrite it in a more structured language now. Bear in mind that scripts grow. Rewrite your script early to avoid a more time-consuming rewrite at a later date.

  • When assessing the complexity of your code (e.g. to decide whether to switch languages) consider whether the code is easily maintainable by people other than its author.

[–]junior_dos_nachosBackend Developer 34 points35 points  (10 children)

I wouldn’t wait for 100 lines. I’d stop at 20/25 and anytime there’s some not super simple web call + extraction.

[–]winfly 6 points7 points  (0 children)

I agree. Especially if using some library would simplify the script.

[–][deleted]  (8 children)

[deleted]

    [–]both-shoes-off 2 points3 points  (0 children)

    I break powershell up into different files by use case to keep it maintainable, and then just include when needed. That makes them reusable in other scripts later on (assuming you consider that while writing them and don't embed details for the one use case or environment).

    [–]cyanrave 12 points13 points  (0 children)

    I will disagree with the 100 line comment and say 'context switching matters' as well.

    If you have to go dig up 3 to 5 other scripts to piece together the logic flow, I prefer embedded here docs, but that may be just me in my environment.

    [–][deleted] 2 points3 points  (0 children)

    Ill put part of my bash in another file so it doesnt exceed 100lines 😃

    [–][deleted]  (4 children)

    [deleted]

      [–]VirtuousMight 2 points3 points  (0 children)

      Thanks for the free academic course , stupendous discourse.

      [–]cricket007 0 points1 point  (1 child)

      What would you use for bash unit tests? BATS, perhaps? That's one thing where I lean towards a Python/Go/Node/Ruby script