469,623 Members | 938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

c programs & shell conditionals

comp.lang.c
c programs & shell conditionals

How is a unix shell script made to respond to the value returned
by a program compiled from c code?
The shell script below is my current effort, which doesn't work.
The c code shows what was used to generate a.out, seen in the shell script.
The value returned was varied from 0 to 1 for testing.
---- shell script
# if [ `/net/u/12/b/br/unet/a.out` 0 ]
if [ `/net/u/12/b/br/unet/a.out` /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi

--- c program
int main(int argc, char **argv)
{
return 1; /* or return 0 or exit(0) or exit(1) */
}

Feb 1 '08 #1
5 1937
In article <fn**********@reader2.panix.com>, Hul Tytus <ht@panix.comwrote:
>if [ `/net/u/12/b/br/unet/a.out` /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi
You just want

if /net/u/12/b/br/unet/a.out
then ...

-- Richard
--
:wq
Feb 1 '08 #2
Hul Tytus wrote:
comp.lang.c
c programs & shell conditionals

How is a unix shell script made to respond to the value returned
by a program compiled from c code?
The shell script below is my current effort, which doesn't work.
The c code shows what was used to generate a.out, seen in the shell
script. The value returned was varied from 0 to 1 for testing.
---- shell script
# if [ `/net/u/12/b/br/unet/a.out` 0 ]
if [ `/net/u/12/b/br/unet/a.out` /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi

--- c program
int main(int argc, char **argv)
{
return 1; /* or return 0 or exit(0) or exit(1) */
}
OT here, comp.unix.programmer or comp.unix.shell might be more apropriate,
but the shell conditionals work diffeent from the C ones, in C non-zero is
true, in shell zero is true.

To make it topical: the only portable return values of main(), resp.
parameters of exit() are 0, EXIT_SUCCESS (which are equivalent) and
EXIT_FAILURE (which usually is 1, but doesn't have to be)

Bye, Jojo
Feb 1 '08 #3
Joachim Schmitz wrote:
Hul Tytus wrote:
>comp.lang.c
c programs & shell conditionals

How is a unix shell script made to respond to the value returned
by a program compiled from c code?
The shell script below is my current effort, which doesn't work.
The c code shows what was used to generate a.out, seen in the shell
script. The value returned was varied from 0 to 1 for testing.
---- shell script
# if [ `/net/u/12/b/br/unet/a.out` 0 ]
if [ `/net/u/12/b/br/unet/a.out` /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi

--- c program
int main(int argc, char **argv)
{
return 1; /* or return 0 or exit(0) or exit(1) */
}
OT here, comp.unix.programmer or comp.unix.shell might be more
apropriate, but the shell conditionals work diffeent from the C ones,
in C non-zero is true, in shell zero is true.
Uhh...perils of answering OT questions...
the `cmd` syntax would require your progarm to print a value. And in that
case redirecting the output to /dev/null doesn't make sense and also you'd
need something to test thie against
To make it topical: the only portable return values of main(), resp.
parameters of exit() are 0, EXIT_SUCCESS (which are equivalent) and
EXIT_FAILURE (which usually is 1, but doesn't have to be)
Bye, Jojo
Feb 1 '08 #4
dbr
Thanks - I had a definite feeling of being in the wrong ball park.

Hul

Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
In article <fn**********@reader2.panix.com>, Hul Tytus <ht@panix.comwrote:
if [ `/net/u/12/b/br/unet/a.out` /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi
You just want
if /net/u/12/b/br/unet/a.out
then ...
-- Richard
--
:wq
Feb 1 '08 #5
Hul Tytus wrote:
comp.lang.c
c programs & shell conditionals

How is a unix shell script made to respond to the value returned
by a program compiled from c code?

<OT>

I recommend, though it's old and possibly out of print, getting hold of
"The Unix Programming Environment" by Kernighan and Pike.

A very short book but, as is usual when Brian Kernighan's involved, a
very clear and useful text. This sort of issue is covered.

</OT>
Feb 1 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by brian.vincent | last post: by
2 posts views Thread by Jorgen Grahn | last post: by
2 posts views Thread by john wright | last post: by
1 post views Thread by Grzegorz ¦lusarek | last post: by
12 posts views Thread by Steve Howell | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.