It is currently Sat, 04 Feb 2023 12:02:16 GMT

Author Message
 capturing an output variable into a shell variable
i am running a shell script that calls a Sybase Stored proc that has
an output parameter. i would
like to capture the value of the output into a shell variable how can
i do this?

 Mon, 27 Dec 2004 00:07:39 GMT   
 capturing an output variable into a shell variable
On 10 Jul 2002 09:07:39 -0700,
  or, in ksh/bash/POSIX shell

 Mon, 27 Dec 2004 01:34:20 GMT   
 capturing an output variable into a shell variable
If your script has one output then echo it at the end

# start of your_script:
do something
echo $xx
#end of your_script

then with


you should get var=something or whatever value xx got in the script.


 Mon, 27 Dec 2004 06:13:21 GMT   
 capturing an output variable into a shell variable

With stored proc execution, you usually get a bunch of dashes as a header
and a return code along with it.  Something like this.

exec <your proc>

The output that gets generated gets put in your ${TEMPFILE}, contents below.


(return status = 0)

Then you could strip away the first 2 lines, which you don't need and then
grab the result in a variable with head and awk.

VAR=`sed '1,2d' ${TEMPFILE} |head -1|awk '{print $1}'`

 Mon, 27 Dec 2004 09:32:01 GMT   
 capturing an output variable into a shell variable

    Three unnecessary external commands.
    None is needed:

      VAR=`{ read; read; read data; echo $data; } < $TEMPFILE`

    Chris F.A. Johnson              
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 Mon, 27 Dec 2004 09:41:58 GMT   
   [ 5 post ] 

Similar Threads

1. Formattet output inside variable / line brak inside variable

2. variable output/variable input

3. file contents into variable, or global variable from shell script

4. Creating shell variable containing substring of another variable.

5. Mixing Shell variables and AWK variables

6. prefixing a shell variable with a variable number of spaces

7. korn shell variable in variable access

8. ENV Shell Variable to Normal Variable Qn

9. difference between shell variable and environment variable

10. Linking Shell Variable with C Variable and vice versa

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software