0

I want a script to run a main.ksh to run both one.ksh and second.ksh only if output of one.ksh matches "1". So if the output is anything other than "1" then second.ksh shouyld not run.

 cat one.ksh
 #!/usr/bin/ksh
 echo "1"

cat second.ksh
#!/usr/bin/ksh

echo "2"

I did this:

#!/usr/bin/ksh

ksh .ksh > one.txt

file="one.txt"

while read line
do

if [ $line -eq 2 ] ;then
ksh second.ksh
else
echo "one.ksh is no good"
fi
done <"$file"

Any better way ro this is good?

1
  • And ... you don't know how to do it? Commented Jun 4, 2013 at 23:14

2 Answers 2

3

Instead of echo 1 to proceed from the first script, you should use exit 0. If it shouldn't proceed, exit 1.

This is the standard way of signaling success and failure in Unix.

Once you do this, you can use any of:

first.ksh && second.ksh

or

if first.ksh
then
    second.ksh
fi

or

set -e  # Automatically exit script if a command fails
first.ksh
second.ksh
Sign up to request clarification or add additional context in comments.

Comments

1
out=`one.ksh`

if [ "x$out" == "x1" ]; then
    second.ksh
fi

1 Comment

You can simplify a bit: [[ "$(one.ksh)" == "1" ]] && second.ksh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.