The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in if statement Swapna173 UNIX for Dummies Questions & Answers 1 03-18-2009 08:00 AM
Error in IF statement ravi214u Shell Programming and Scripting 4 07-14-2008 10:44 AM
error in if statement capri_drm Linux 16 05-14-2008 02:00 PM
Error with if statement..Please help jisha Shell Programming and Scripting 1 01-16-2008 07:13 AM
while read loop w/ a nested if statement - doesn't treat each entry individually littlefrog Shell Programming and Scripting 7 12-11-2007 09:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-09-2009
reubenpatterson reubenpatterson is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
Nested If Statement Error

I'm new to shell scripting and trying my hand with nested if statements, and it seems to work fine until I try to test for an input of filename, then I get "line 40: syntax error near unexpected token `fi'"

I just can't see what's different between having 2 ifs and when I add the 3rd. Any help would be appreciated.

-----------------------code----------------
#/bin/sh
set -v on
set -x on

echo "What content file are you going to run?"
read file
echo "What expiration date? Enter in 01-APR-09 format."
read expired


if [ "$file" = "" ]; then

echo "Need a filename to process."

else

for asset in ${list[@]}; do
list=( `cat $file`)
result1=( `sqlplus -S user/pass@db1 << EOF
set pages 0 echo off verify off feedback off
select package_name from package where package_id = (select substr(path, -20) from content where file_name = '$asset');
exit
EOF`)

if [ "$result1" = "" ]; then

echo $asset
else

result2=( `sqlplus -S use/pass@db2 << EOF
set pages 0 echo off verify off feedback off
select expiration_date from offering where package_name='$result1' and expiration_date > '$expired';
exit
EOF`)
if [ "$result2" = "" ]; then

echo $asset
fi
fi
fi
done
  #2 (permalink)  
Old 05-09-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 730
When coding indentation is your friend, I think your last fi and done need to be swapped thus:
Code:
#/bin/sh
set -v on
set -x on

echo "What content file are you going to run?"
read file
echo "What expiration date? Enter in 01-APR-09 format."
read expired


if [ "$file" = "" ]; then

  echo "Need a filename to process."

else

  for asset in ${list[@]}; do
    list=( `cat $file`)
    result1=( `sqlplus -S user/pass@db1 << EOF
    set pages 0 echo off verify off feedback off
    select package_name from package where package_id = (select substr(path, -20) from content where file_name = '$asset');
    exit
EOF`)

    if [ "$result1" = "" ]; then

      echo $asset
    else

      result2=( `sqlplus -S use/pass@db2 << EOF
      set pages 0 echo off verify off feedback off
      select expiration_date from offering where package_name='$result1' and expiration_date > '$expired';
      exit
EOF`)
      if [ "$result2" = "" ]; then

        echo $asset
      fi
    fi
  done
fi
  #3 (permalink)  
Old 05-09-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

When you post code, please wrap it in [code] tags or the indentation will not be visible.
Quote:
-----------------------code----------------
Code:
                EOF`)

EOF must be on a line by itself and at the beginning of the line (unless you use <<-EOF in which case it may be preceded by TAB).
  #4 (permalink)  
Old 05-09-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 730
I've just ordered your book Mr. Johnson, look forward to reading it.

Are you saying the:
Code:
EOF`)
should be:
Code:
EOF
`)
?

Also if sqlplus does not like white space at the beginning of its commands then the lines after the "<<EOF" and before the terminating "EOF" should not be indented, but not sure about whether sqlplus would object to white space or not!
  #5 (permalink)  
Old 05-09-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by TonyFullerMalv View Post
I've just ordered your book Mr. Johnson, look forward to reading it.

Thanks very much. I hope you find it useful.
Quote:

Are you saying the:
Code:
EOF`)
should be:
Code:
EOF
`)
?

Right.
Quote:

Also if sqlplus does not like white space at the beginning of its commands then the lines after the "<<EOF" and before the terminating "EOF" should not be indented, but not sure about whether sqlplus would object to white space or not!

You can indent with tabs if you use <<-EOF. The tabs will be stripped.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0