[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing variables to and from custom programs
From: |
Mike Stroyan |
Subject: |
Re: Passing variables to and from custom programs |
Date: |
Sun, 7 Feb 2010 11:05:08 -0700 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Sat, Feb 06, 2010 at 05:35:21PM -0800, DennisW wrote:
> On Feb 6, 5:37 pm, djackn <jack.nadel...@yahoo.com> 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=$?
--
Mike Stroyan <mike@stroyan.net>