On Fri, 11 Feb 2022 20:20:04 +0000, Billy Ashton wrote:

>Hey everyone...I am having a tough time with a shell script I am writing 
>for my BPXBATCH step. All I want to do is run one of two commands 
>depending on a variable that is passed to the script.
>
(This might be more topical on MVS-OE.)
(You'd do better to test scripts interactively before introducing
the complexity of BPXBATCH.)

>I have tried coding
>if [ "$pet" == "DOG" ] ; then
>    commands...
>else
>    other commands
>fi
>
See:
<https://www.ibm.com/docs/no/zos/2.5.0?topic=structures-using-test-command-test-conditions>

My attempt:
536 $ cat comp
#! /bin/sh -x
if [ "DOG" = "$pet" ] ; then
    echo commands...
else
    echo other commands
fi
537 $ 
Results:
534 $ pet=DOG ./comp
comp 2+ '[' DOG = DOG ']'
comp 3+ echo commands...
commands...
535 $ 
535 $ pet=cat ./comp
comp 2+ '[' DOG = cat ']'
comp 5+ echo other commands
other commands
536 $ 

Pro tip:  Code the constant first lest the value of a variable
be mistaken for a prefix operator.

-- 
gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to