I thought it's very irrational to abuse the test statement rather than using a case statement for string comparison in a shell script, in viewpoint of portability and performance.

1 Answer 1


What if your view of writing for "performance and portability" doesn't match the goal? What if you're writing scripts to be understood by next summer's intern? Scripts whose runtime is so short that performance doesn't count? (what do you gain by a 99% reduction in a .001 second script's runtime?) Scripts for my special hardware/software environment?

There are many different philosophies of development. The determination of "best" for each environment is a Matter of Opinion.

Since you don't offer any data about performance ("Here's how long 100000 executions of each syntax took") or about portability ("Here's a survey of how many systems don't support each syntax"), all you're left with is opinion.

  • 1
    This "answer" is an opinion too...
    – the_endian
    Feb 19, 2021 at 16:04

You must log in to answer this question.