If..else command gives error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If..else command gives error
# 1  
Old 08-23-2007
If..else command gives error

Hi,
I am a newbie and was getting an error when I use the if..else syntax. The script looks like this

echo "Please specify the database version (9i/10g): "
read VERS
if [ "$VERS"="9i" ]
then
echo "Its a 9i Database"
sqlplus -s $puser/$ppass << EOF_I
spool cxcreate9i.lst
@ cxtool/1.1/scripts/backend/cxcreate;
spool off
exit;
EOF_I
else
echo "Its a 10g Database"
fi


Now when I execute it I get the following error:
./test.sh: line 17: syntax error: unexpected end of file

If I remove the if else syntax and just put the middle portion in the script, it executes fine.

sqlplus -s $puser/$ppass << EOF_I
spool cxcreate9i.lst
@ cxtool/1.1/scripts/backend/cxcreate;
spool off
exit;
EOF_I

I am not able to understand what am I doing wrong here.

Thanks
# 2  
Old 08-23-2007
Are you indenting the code between "sqlplus" and "EOF_I" in some way?

The closing "EOF_I" clause MUST be at the beginning of the line (no white spaces before).
Also, you may remove the space between "<<" and "EOF_I", or try:

Code:
echo "Please specify the database version (9i/10g): "
read VERS
if [ "$VERS"="9i" ]
then
   echo "Its a 9i Database"
   sqlplus -s $puser/$ppass <<-EOF_I
   spool cxcreate9i.lst
   @cxtool/1.1/scripts/backend/cxcreate;
   spool off
   exit;
EOF_I
else
   echo "Its a 10g Database"
fi

# 3  
Old 08-23-2007
Not sure what is going wrong, but just try this:

Code:
echo "Please specify the database version (9i/10g): "
read VERS
if [[ "$VERS" = "9i" ]]; then
echo "Its a 9i Database"
sqlplus -s  $puser/$ppass << EOF
spool cxcreate9i.lst
@ cxtool/1.1/scripts/backend/cxcreate;
spool off
exit;
EOF
else
echo "Its a 10g Database"
fi

# 4  
Old 08-23-2007
Oh shoot...you got it right on...I was using one of the editors which looked nice with indented code. It works if i remove the indents.

Thanks a million robotronic..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

2. Shell Programming and Scripting

Syntax error with ps command

i am trying the blow command in vain on Linux Terminal. kill -9 `ps -eaf | grep weblogic.NodeManager | grep wls103 | awk '{print $2}'` kill: usage: kill pid | jobspec ... or kill -l kill -9 $(ps -eaf | grep weblogic.NodeManager | grep wls103| awk '{print $2}') kill: usage: kill pid |... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. UNIX for Advanced & Expert Users

AT command Error

Hi I have used the AT command in my shell script to schedule the jobs. Sometimes it works fine but sometimes it throws an error, such as : at: can't change the owner of your job to you. I could not find any solution to this issue yet. If anyone can please provide any pointer what doe this... (3 Replies)
Discussion started by: MD21
3 Replies

4. UNIX for Dummies Questions & Answers

Nail command error

Hello all. I am currently using Red Hat Enterprise Linux Server release 5.8 (Tikanga). I have multiple users on this system and intend to use nail command to send out emails. When I enter the command: nail <some-email-address> its accepts the command and sends out an email. But when I... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

5. Shell Programming and Scripting

find command error

Hi, We have a shell script which looks into a directroy for any folder older than 30 days and removes them. The command being used is find $ARCHIVE_DIR -type d -mtime +$PURGE_HIST_DAYS -exec rm -rf {} \; It removes some folders but then throw below errors for others: find:... (2 Replies)
Discussion started by: DejaVu
2 Replies

6. Shell Programming and Scripting

Linux Command Error for nawk command

Hi All We are migrating our projects from unix environment to linux. I tried running a install script which sets up my project, i.e. the directory structure and all. But in the middle of the script i started receiveing following error : nawk: command not found . So i need to know which... (1 Reply)
Discussion started by: vee_789
1 Replies

7. Shell Programming and Scripting

command not found error

hello every time i run the following code for val in fileX fileY fileZ do $val=`ls -l $val | awk '{print $5}'` done i got error message command not found , i tried to add ' and " but nothing works its only worked wen remove $val= but i want the name of the file and the value ... (9 Replies)
Discussion started by: mogabr
9 Replies

8. Shell Programming and Scripting

Error with using a shell command(looks more generic error)

Hi, This error is actually out of implementing the command posted here - https://www.unix.com/shell-programming-scripting/155589-remove-blank-lines-merge-lines-shell.html Here is the error i get - awk: Input line xxxxx cannot be longer than 3,000 bytes. The source line number is 1.... (1 Reply)
Discussion started by: dvah
1 Replies

9. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

10. Shell Programming and Scripting

sed command error

Hi, Could some one help me please ? When I execute this command # paste -s -d"^m" swagent.log | sed '{s/\"\./\"\.\n/g}' > swagent.new I get this error. sed: Function {s/\"\./\"\.\n/g} cannot be parsed. Many Thanks in advance Regards, Nagu (1 Reply)
Discussion started by: srnagu
1 Replies
Login or Register to Ask a Question