this post was submitted on 05 Mar 2025
1064 points (99.0% liked)
Programmer Humor
27500 readers
1487 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
It all makes sense when you think about the way it will be parsed. I prefer to use newlines instead of semicolons to show the blocks more clearly.
The
doanddoneserve as the loop block delimiters. Such as{and}in many other languages. The shell parser couldn't know where stuff starts/ends.Edit: I agree that the
then/fi,do/donecase/esacare very inconsistent.Also to fail early and raise errors on uninitialized variables, I recommend to add this to the beginning of your bash scripts:
Or only this for regular sh scripts:
-e: Exit on error-u: Error on access to undefined variable-o pipefail: Abort pipeline early if any part of it fails.There is also
-xthat can be very useful for debugging as it shows a trace of every command and result as it is executed.