How to use select into command in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use select into command in shell script?
# 8  
Old 12-22-2011
Still I'm getting the same error after moving the EOF` to separate lines.

Below is the error when i used if condition suggested by you,

line 25: syntax error near unexpected token `fi
line 25: `fi'


I am a newbie to shell scripting. Please help.
# 9  
Old 12-22-2011
Can you paste the code you have used?
Also, echo the variable $outputvar... I have a feeling, there might be a newline in it...

Probably you can paste the output of sh -x <your script>

--ahamed

Last edited by ahamed101; 12-22-2011 at 11:13 AM..
# 10  
Old 12-22-2011
Code:
#!/bin/sh
outputvar=`sqlplus -S $username/$password@$tnsname << EOF
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
select count(*) from table;
exit;
EOF
`
echo "value is "$outputvar
if [ $outputvar -gt 0 ]; then
  echo "value is larger" 
else
  echo "Not larger.."
fi

O/p
Code:
value is  52365
test.sh: line 25: syntax error near unexpected token `fi'
test.sh: line 25: `fi'

I have got the same error when i tried with while loop as well.
# 11  
Old 12-22-2011
Paste the output of sh -x <your script>, that should help!

--ahamed
# 12  
Old 12-22-2011
Please find the same here
Code:
++ sqlplus -S $'dev/dev\orcl'
' outputvar='    52365
+ echo 'value is ' $'52365\r\r'
value is  52365
test.sh: line 25: syntax error near unexpected token `fi'
test.sh: line 25: `fi'

# 13  
Old 12-22-2011
There is a carriage return! Try this...

Code:
outputvar=`echo $outputvar | sed 's/\r//g' `
if [ ...

--ahamed
# 14  
Old 12-22-2011
Still the same error. Please find the modified code and o/p Smilie

Code:
#!/bin/sh
outputvar=`sqlplus -S $username/$password@$tnsname << EOF
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
select count(*) from table;
exit;
EOF
`
outputvar=`echo $outputvar | sed 's/\r//g' `
echo "value is "$outputvar
if [ $outputvar -gt 0 ]; then
  echo "value is larger" 
else
  echo "Not larger.."
fi

O/P

Code:
' outputvar='    52365
++ echo $'52365\r'
++ sed 's/\r//g'
+ outputvar=$'52365\r'
' echo 'value is 52365
value is 52365
test.sh: line 26: syntax error near unexpected token `fi'
test.sh: line 26: `fi'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying the shell script to select pattern

Hello, I have script which work 70% of the desired task , the output from script.sh is following , however the desired output I require is following . Any piece of suggestion would be great.. thanks in advance, emily #!/bin/bash ... (8 Replies)
Discussion started by: emily
8 Replies

2. Shell Programming and Scripting

Select answers from multiple questions using shell script

I have a text file in this format Some lines.... Question no: 1 The question? A. Answer 1 B. Answer 2 C. Answer 3 D. Answer 4 Answer:B Some lines.... Question no: 2 The question? (choose 2) (10 Replies)
Discussion started by: zorrox
10 Replies

3. Shell Programming and Scripting

Select command going to infinite loop after running the script

cd /opt/et/WAS/apps/8.0 find . -name "HostIntegration.properties" -o -name "HostSocket.properties" -o -name "environment.properties" 2> /dev/null | awk -F '' '{print $4}'|awk '!x++' | cat>/home/cbadmin/file1.txt cd /home/cbadmin/ PS3='Please enter a number from list of applications==>:' select... (3 Replies)
Discussion started by: bhas85
3 Replies

4. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

5. Shell Programming and Scripting

How to pass Variable from shell script to select query for SqlPlus?

echo "set echo off"; echo "set feedback off"; echo "set linesize 4000"; echo " set pagesize 0"; echo " set sqlprompt ''"; echo " set trimspool on"; Select statement is mentioned below echo "select res.ti_book_no from disney_ticket_history res where res.ti_status =${STATUS} and... (7 Replies)
Discussion started by: aroragaurav.84
7 Replies

6. Shell Programming and Scripting

How to print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

7. Shell Programming and Scripting

Select combination unique using shell script

Hi All, bash-3.00$ gzgrep -i '\ ExecuteThread:' /******/******/******/******/stdout.log.txt.gz <Jan 7, 2012 5:54:55 PM UTC> <Error> <WebLogicServer> <BEA-000337> < ExecuteThread: '414' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "696" seconds working on the request... (4 Replies)
Discussion started by: osmanux
4 Replies

8. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

9. Shell Programming and Scripting

using SELECT sql statement in shell script

Hi there I have a database on a remote box and i have been using shell script to insert data into it for example, i could have a script that did this SN=123456 n=server1 m=x4140 sql="UPDATE main SET hostname='$n',model='$m' WHERE serial='$SN';" echo $sql |/usr/sfw/bin/mysql -h... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

10. Shell Programming and Scripting

Supress ' quotes in a select statement inside Shell Script

Hi I have a shell script in which a string variable is saving following query. SqlQuery="select a||'|'||b||'|'||c from dual" I am trying to pass above query as a parameter to some script but its giving me error for "single quote". I tried suppressing it using \' instead of just ' but it... (1 Reply)
Discussion started by: mahabunta
1 Replies
Login or Register to Ask a Question