Hello,
I want to run 2 independent 'if else fi' statements in one script, like given below. Individually I have each script-set working perfectly but cannot get them together to run one after the other. On the net I only got examples of nested ones.
if queryA ; then echo Output1 else echo output2 fi
if queryB ; then echo output3 else echo output4 fi
They are not nested if else statements. They running independently in a common script. They have no relation with each other.
I am getting syntax errors for 'fi'. What is the correct syntax for the above combination? Thanks in advance for any help.
I want to run 2 independent 'if else fi' statements in one script, like given below. Individually I have each script-set working perfectly but cannot get them together to run one after the other. On the net I only got examples of nested ones.
Which shell are you using?
-Shamit http://shamit.in/dpal
On 08/07/2010 01:11 AM, Rony wrote:
Hello, [...snip...] if queryA ; then echo Output1 else echo output2 fi
if queryB ; then echo output3 else echo output4 fi
[...snip...] I am getting syntax errors for 'fi'. What is the correct syntax for the above combination? Thanks in advance for any help.
That looks right. What is the exact error you get ?
cheers, - steve
On Sat, Aug 7, 2010 at 6:52 AM, steve steve@lonetwin.net wrote:
On 08/07/2010 01:11 AM, Rony wrote:
Hello, [...snip...] if queryA ; then echo Output1 else echo output2 fi
if queryB ; then echo output3 else echo output4 fi
[...snip...] I am getting syntax errors for 'fi'. What is the correct syntax for the above combination? Thanks in advance for any help.
That looks right. What is the exact error you get ?
$ cat test.sh #!/bin/bash
if [ "$1" == 1 ] ;then echo "statement 1" else echo "statement 3" fi
if [ "$2" == 2 ] ;then echo "statement 2" else echo "statement 4" fi $ ./test.sh statement 3 statement 4 $ ./test.sh 1 2 statement 1 statement 2
I don't see any error in this.
$ bash --version GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu) Copyright (C) 2007 Free Software Foundation, Inc.
HTH