bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing variables to and from custom programs


From: Chris F.A. Johnson
Subject: Re: Passing variables to and from custom programs
Date: Sun, 7 Feb 2010 16:29:34 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Sun, 7 Feb 2010, Mike Stroyan wrote:

> On Sat, Feb 06, 2010 at 05:35:21PM -0800, DennisW wrote:
> > On Feb 6, 5:37 pm, djackn <address@hidden> wrote:
> > >     Result = myIpExec(${IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4})
> > >
> > > myIpExec is a c program that normally uses scanf to prompt the user
> > > for the IP addresses and returns 0 or 1.
> > > I plan to use the script to test the program for various inputs.
> > 
> > It is more likely that this would work:
> > 
> > Result=$(echo "{IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4}" | myIpExec)
> > 
> > Note that there are no spaces around the equal sign.
> 
>   If the result of 'myIpExec' is output to stdout then you could put that into
> a shell variable with the syntax that DennisW showed you.  But you may have a
> problem with parsing it because any prompt for the IP addresses will be 
> included
> at the front of that variable.
> 
>   If the result of 'myIpExec' is actually a return value from main() then you
> would access that as the shell variable $? just after the program is run.
> 
>   The bash 'here string' notation could be used as an alternative to the
> echo pipeline notation.  It is not as portable.  But I like the way it looks
> in shell script.  It is used like this-
> 
> myIpExec <<< "{IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4}"
> Result=$?

   The portable equivalent is:

myIpExec <<EOF
{IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4}
EOF

-- 
   Chris F.A. Johnson                          <http://cfajohnson.com>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]