sh - How to negate multiple conditions in the Bourne shell -


i have simple bourne shell script this:

if ! pwd && ls && mkdir /opt/test/;     echo "failure" else     echo "success" fi 

i want report failure if of commands not exit e.g. if mkdir command fails due insufficient permissions. therefore, negation should cover 3 commands.

how do this?

you reverse sense of test:

if pwd && ls && mkdir /opt/test/;     echo success else     echo failure fi 

this can problem if don't have commands run success case, because it's syntax error leave out block. can use true or : (an alias true) do-nothing command:

if [ -d "$directory" ] || mkdir "$directory";     : directory exists else     echo not create "$directory"; exit 1 fi