by chatmasta · 3y ago · 0 comments
I picked up the habit of preferring `test` when I was writing scripts that needed to run in both `sh` and `bash`, but I kept it because it makes more semantic sense to me than treating a character like `[` as a command. It's also weird that `]` is an argument to `[` rather than also being a binary. I mean, I understand the technical reasoning... but it feels like a hack.
yelp(){
es=$1
shift
echo "$@" >&2
exit $es
}
test -d /tmp/goober || yelp 33 "couldn't find goober!"
(yes, I'm sure there are standards for exit status ranges and 33 is not such a thing)https://google.github.io/styleguide/shellguide.html#s6.3-tes...
In a scenario where you also need to support shells other than bash, Google’s shell style guide doesn’t say to use [ over test.