dimanche 21 juillet 2019

Shell if-statement vs brackets-style reasoning

Are these 2 POSIX-ly correct versions of an example if's:

if-statement

#!/bin/sh
if [ "$#" -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
    ...
fi

brackets-style

the very same:

#!/bin/sh
{ [ "$#" -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; } &&
{
    ...
}


is there any other argument against using the latter than a little less of readability? like performance or whatever.

reason for me asking is just curiosity and a better understanding of control structures.

the contents of that example are irrelevant, I care only for the structure

Aucun commentaire:

Enregistrer un commentaire