It is currently Fri, 15 Oct 2021 20:03:15 GMT



 
Author Message
 ksh test short-circuiting?
I am having a peculiar problem.
I had the following line in my ksh program.

if [ \( "$1" -lt 0 -o "$2" -lt 0 \) -o \( "$#" -eq 3 -a "${3}" -lt 0 \) ] ; then
        echo "$0: values must all be positive" >&2
        return 3
fi

It worked just fine.

Then I put:
#! /bin/ksh

# Purpose: To generate some data
# Original Author: HR Puffnstuff

mystuff () {
if [ \( "$1" -lt 0 -o "$2" -lt 0 \) -o \( "$#" -eq 3 -a "${3}" -lt 0 \) ] ; then
        echo "$0: values must all be positive" >&2
        return 3
fi

# do some work

return 0

and I dot-ed it into my environment.  When I try to use it, I get the error:

mystuff: 3: parameter not set

and until I change the if into 3 statements, where the $3 reference is
shielded by code which cannot be reached unless there are 3 arguments, the
error remains.

Anyone know if this is intentional - should test work differently in
functions than in programs?
--
Larry W. Virden                 UUCP: osu-cis!chemabs!lwv27
Same Mbox: BITNET: lwv27@cas    INET: lwv27%cas.BIT...@CUNYVM.CUNY.Edu
Personal: 674 Falls Place,   Reynoldsburg,OH 43068-1614
America Online: lvirden



 Fri, 25 Feb 1994 18:42:21 GMT   
 
   [ 1 post ] 

Similar Threads

1. Need short circuit for boot sequence

2. short-circuiting name resolution in 4.1.3

3. 264 DP, a short circuit, an environmental threat?

4. Need fix for short ksh script

5. test test test test test test test

6. Short Test Kill Filesystem!

7. Translating Sun short binary to linux short binary?

8. What port # is for short accepting short messages?

9. test test test test

10. ksh/bash: let cmd and test cmd interpret 08 (octal) differently


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software