DEV Community

Discussion on: Bash from scratch: learn enough bash to write your own scripts

Collapse
 
erebos-manannan profile image
Erebos Manannán • Edited

Instead of referring to some online articles on test conditions, you can just check out man test.

Conditions and most other such things are good to shorthand a bit, and if you're planning on using BASH use [[ ... ]] instead of [ ... ] as they also function differently. Stick to one style for predictability. serverfault.com/a/52050

Slightly compacted formats

if [[ "$FOO" == "1" ]]; then
  ...
else
  ...
fi

for i in 1 2 3 4; do
  echo $i
done

while [[ true ]]; do
  ...
done

Also shellcheck.net/ is an excellent resource to use to check your scripts for common bugs etc. There's even a decent unit testing framework for BASH scripts nowadays: github.com/sstephenson/bats

Collapse
 
ahmedmusallam profile image
Ahmed Musallam

I have updated the post, thank you again for the feedback!

Collapse
 
ahmedmusallam profile image
Ahmed Musallam

This is fantastic! I’m still new to bash scripting :) but will include this in the article. Great feedback!!