Set shell variable from command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set shell variable from command
# 1  
Old 03-14-2012
Set shell variable from command

shell script has a command inside back quotes in method update_TABLE
I need to store the count of number of Rows updated and store it in shell script variable "num"


Code:
num = 0;
Update_TABLE

Update_TABLE()
{
       
       `echo "  set verify off feedback off echo off pagesize 0 head off
       whenever sqlerror exit 99
               UPDATE FILE
               SET FILE_STATUS='$FSTATUS' , FILE_NAME='$FILE_NAME',
SYS_UPDATE_DATE = SYSDATE
               WHERE IDENTIFIER='$IDENTIFIER' AND FILE_STATUS='RD';              
               commit;
               exit;
       "| sqlplus -s $USER `


       if [ $? -ne 0 ]
       then
               echo "\tError: problem occured while updating file
status to '$FSTATUS'"
               echo "\tError: FileName=$FILE_NAME"
               Exit 2
       fi


}

please suggest how to set num inside sqlplus part ?
Thanks
# 2  
Old 03-14-2012
Code:
num=0;
num=$(Update_TABLE | awk '{print $1}')
echo $num
Update_TABLE()
{
       res=$(echo "  set verify off echo off pagesize 0 head off
       whenever sqlerror exit 99
               UPDATE FILE
               SET FILE_STATUS='$FSTATUS' , FILE_NAME='$FILE_NAME',
  SYS_UPDATE_DATE = SYSDATE
              WHERE IDENTIFIER='$IDENTIFIER' AND FILE_STATUS='RD';
              commit;
               exit;
       "| sqlplus -s $USER)
       if [ $? -ne 0 ]
      then
              echo "\tError: problem occured while updating file status to '$FSTATUS'"
              echo "\tError: FileName=$FILE_NAME"
              Exit 2
       fi
        echo $res
}

# 3  
Old 03-14-2012
Pravin, this is not working because there is no SELECT Statement.
It has only UPDATE and there is no display inside sql command block.

I know that we can use sql%rowcount to know number of rows updated, but how can we pass this rowcount to shell ..
# 4  
Old 03-14-2012
Finder255, Please check code again.. I have removed the feedback off option.
# 5  
Old 03-14-2012
PERFECT . Thanks Pravin Smilie
however, I am not able to understand how UPDATE is returning Count of updated rows.. In forums I read, one has to do specifically "SQL%rowcount" to do this..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script set command to a variable

Hi, Will following set up work in bash script? I've got errors if assigning following binary command to a variable. But on the other hand, COMMAND="ls" works. Any explanation please? How can I assign binary command to a variable COMMAND then I can just call ${COMMAND}? COMMAND="rsync"... (3 Replies)
Discussion started by: hce
3 Replies

2. Shell Programming and Scripting

set variable with square brackets in c shell!

Hi Guys, I want to set a variable which happend to have square brackets in them. I tried multiple ways that is by escaping it with quotes (both single and double ) but it didn't help. All I want is: set x = slicearray.slice\.post My failed attempts were: set x = "slicearray.slice\.post"... (3 Replies)
Discussion started by: dixits
3 Replies

3. Shell Programming and Scripting

how to set/get shell env variable in python script

greetings, i have a sh script that calls a python script. the sh script sets an env variable BIN: export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
Discussion started by: crimso
5 Replies

4. HP-UX

What is the use of command set -- and set - variable?

Hi, I am using hp unix i want to know the use of the following commands set -- set - variable thanks (4 Replies)
Discussion started by: gomathi
4 Replies

5. Shell Programming and Scripting

set variable to command output

I'm hoping you guys can help me out here. I've been trying different methods to try and get what IW as hoping would be a fairly simple script but has turned into a pain. Bit of background - I am writing a script to check values in certain failes to ensure they are corerct. I'm runnign this on... (2 Replies)
Discussion started by: stuc
2 Replies

6. Shell Programming and Scripting

set variable with another variable? c shell

okay, this shouldn't be difficult but I can't figure it out. How can I set a variable with another variable. I have the following: foreach pe ($dir $sp) set tpe = `echo $pe | grep M` if ($tpe == M) then set ${$pe} = M <--- This doesn't work else endif end In this case what... (2 Replies)
Discussion started by: wxornot
2 Replies

7. Shell Programming and Scripting

How to make nawk to set a shell variable

Below is the content of the file I am parsing bash-2.03$ cat rakesh cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/gmon.o", errno 28, No space left on device cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/README", errno 28, No space left on device... (1 Reply)
Discussion started by: rakeshou
1 Replies

8. Shell Programming and Scripting

set variable command

Hi all, I want to set a variable in ksh shell (prompt) and echo the value. $ set x=5 $echo $x But it is returning null. Can any one please help. Thanks in advance (1 Reply)
Discussion started by: ammu
1 Replies

9. UNIX for Dummies Questions & Answers

Export command giving Variable Name vs the Value set for the Variable

I'm having an issue when I export within my program. I'm getting the variable name, not the variable value. I have a configuration file (config.txt) that has the values of the variables set as so: set -a export ARCHIVEPOSourceDir="/interfaces/po/log /interfaces/po/data" export... (2 Replies)
Discussion started by: ParNone
2 Replies

10. Shell Programming and Scripting

Set Path variable in c shell

I set my path environment variable in c shell, using the syntax below setenv PATH "${PATH}:/usr/local:/usr/local/bin" and placed this in $HOME/.login $HOME/.cshrc and /etc/.login /etc/.cshrc but when I issued echo $PATH or set command the output does not reflect changes made to... (5 Replies)
Discussion started by: hassan2
5 Replies
Login or Register to Ask a Question