why isn't the exit status true?

the code:

do
[ -d ${mk_backup_dir[$i]} ] || mkdir -p ${mk_backup_dir[$i]}
[ $? -ne 0 ] && echo "ERROR: release backup directory creation failed -${mk_backup_dir[$i]}" && exit
done

echo "INFO: Backup directories created"

the result:

mkdir: "/cm/uat_releases/riab/uat/2345": Permission denied
ERROR: release backup directory creation failed - /cm/uat_releases/riab/uat/2345
No such file or directory

INFO: Backup directories created

isn't the exit status of the first command on the 3rd line 'true', so therefore the script will exit '&& exit'? but it doesn't, it carries on and displays 'Backup directories created'.

why?

have you echoed $? to see what is returned?

[ -d ${mk_backup_dir[$i]} ] || mkdir -p ${mk_backup_dir[$i]}
echo $?

You could also use debugging

#!/usr/bin/ksh
{
set -x 
do
[ -d ${mk_backup_dir[$i]} ] || mkdir -p ${mk_backup_dir[$i]}
[ $? -ne 0 ] && echo "ERROR: release backup directory creation failed -${mk_backup_dir[$i]}" && exit
done

set +x
} >> outputlog 2>&1

$? = 2. which is not zero. therefore '&& echo "Error:....' gets displayed and then the exit should follow.

mmmmm you're right the exit should follow
I've just tested it using this

#!/usr/bin/ksh
{
set -x
arg=0
while [[ $arg -le 1 ]]
do
[ -d /cm/uat_releases/riab/uat/2345 ] || mkdir -p /cm/uat_releases/riab/uat/2345
[ $? -ne 0 ] && echo "ERROR: release backup directory creation failed -/cm/uat_releases/riab/uat/2345" && exit
(( arg +=1 ))
done

echo "INFO: Backup directories created"
set +x
}>> ouptput 2>&1

It DOES work and exits WITHOUT displaying

INFO: Backup directories created

my debugging info was

 arg=0
+ [ -d /cm/uat_releases/riab/uat/2345 ]
+ mkdir -p /cm/uat_releases/riab/uat/2345
mkdir: cannot create directory `/cm': Permission denied
+ [ 1 -ne 0 ]
+ echo ERROR: release backup directory creation failed -/cm/uat_releases/riab/uat/2345
ERROR: release backup directory creation failed -/cm/uat_releases/riab/uat/2345
+ exit

btw my machine details are Linux fhinux 2.6.5-7.191-default #1 Tue Jun 28 14:58:56 UTC 2005 i686 i686 i386 GNU/Linux

and i'm using korn

i got it to work. it's my fault.

in the script, i'm using a function called 'display_message' instead of 'echo'. i omitted this from my post and replaced it with 'echo' because i couldn't be bothered to explain the function.

$LOGFILE isn't setup properly yet, so i was actually getting an error before '&& exit' was reached. somehow - not sure how though - this was causing the '&& exit' to be ignored.

thanks offsihr, because it was from running your version of the script that helped me realise my mistake.

you're welcome.
sometimes it's easier when someone else does a cut down.
I'm guessing short circuit evaluation meant the whole expression wasn't evaluated

[ $? -ne 0 ] && echo "ERROR: release backup directory creation failed -/cm/uat_releases/riab/uat/2345" && exit
TRUE---------------------->FALSE------------------------------------------> no more is evaluated

as && needs all to be true