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,
 variable=`script`
  or, in ksh/bash/POSIX shell
 variable=$(script)


 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

e.g
# start of your_script:
do something
...
xx='something'
echo $xx
#end of your_script

---------------------------------
then with

var=`your_script`

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

regards



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

news:b2791e11.0207100807.4bfb5057@posting.google.com...

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

isql -S<DATASERVER> -U<LOGIN> -w999 <<-EOF ${TEMPFILE}
${PASSWORD}
exec <your proc>
go
EOF

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

result
---------------
593838293

(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                        http://cfaj.freeshell.org
    ===================================================================
    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