Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2002 22:34:51 +0100
From:      David Dooley <dpd@raffles-it.com>
To:        David.Dooley@E-Peopleserve.com, freebsd-questions@freebsd.org
Subject:   KSH Shell Script Logic problem
Message-ID:  <20020911223451.2903ba62.dpd@raffles-it.com>

next in thread | raw e-mail | index | archive | help
Hi,

I am trying to write a shell script using the ksh. 

	a section of the script goes as follows, variables changed to
	protect the innocent :-)

	# Input file will have 2 elements per line seperated by a colon (:),
	# one or other element may be empty
 	IFS=\:

	# Read line from file assign first element to VariableA and the
	# second element to VariableB
	
	cat config_file | while read VariableA VariableB
	do
		# Make sure that VariableA and B are assigned a value, if 
		# nothing was read from the input, that can be checked, 
		# so we are not mucking around and trying to do test's 
		# with NULL's.
		VariableA=${VariableA:=UNSET}
		VariableB=${VariableB:=UNSET}

		[[ ${VariableA} != UNSET && ${VariableB} != UNSET ]] && {
			call function 
			# check return code
			[[ ${?} -ne 0 ]] && {
				Echo Diagnostic error message
			}
		} || {
			[[ ${VariableA} != literal || \
				 ${VariableB} != literal ]] && {
				Echo diagnostic error message
			}
		}
	done

In this scenario if 	
	[[ ${VariableA} != UNSET && ${VariableB} != UNSET ]]
evaluates to true and we drop into the '&&' part of the test, and if the
nested second test evaluates to true all is happy and right with the world,
but if the second nested test fails then the outer test's '||' part is run, but
if I put an '||' part on to the nested test to catch that failure then the
first tests '||' part is not run, please could some one tell me why with out
the nested tests '||', I get the outer tests '||' part run.

I really hope that the previous paragraph makes sense, It only just about
makes sense to me and I wrote it.

Please could you include me on any answers as I am not subscriped to the list
from this email address, thanks for your time and any assistance.

David.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020911223451.2903ba62.dpd>