|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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) */ } |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:
>comp.lang.c > 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. [re-ordered] >--- c program >int main(int argc, char **argv) >{ > return 1; /* or return 0 or exit(0) or exit(1) */ >} Nothing wrong here, except that EXIT_FAILURE is probably better than 1 (though there's a good chance that the value of EXIT_FAILURE is in fact 1 on your platform). >---- shell script ># if [ `/net/u/12/b/br/unet/a.out` > 0 ] >if [ `/net/u/12/b/br/unet/a.out` > /dev/null ] The people in comp.unix.shell will probably tell you that this line is wrong. dave -- Dave Vandervies dj3vande at eskimo dot com Their failure is not your excuse; time to find an unaverage pub. --Richard Bos in the scary devil monastery |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:
>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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Thanks Jojo - I'll give that a try. Do you know what .h file contains
the definitions for EXIT_xxx? Hul Joachim Schmitz <nospam.jojo@schmitz-digital.de> 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. > 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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Thanks - I had a definite feeling of being in the wrong ball park.
Hul Richard Tobin <richard@cogsci.ed.ac.uk> wrote: > In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote: > >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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Thanks, Hul
dj3vande@csclub.uwaterloo.ca.invalid wrote: > In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote: > >comp.lang.c > > 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. > [re-ordered] > >--- c program > >int main(int argc, char **argv) > >{ > > return 1; /* or return 0 or exit(0) or exit(1) */ > >} > Nothing wrong here, except that EXIT_FAILURE is probably better than 1 > (though there's a good chance that the value of EXIT_FAILURE is in fact > 1 on your platform). > >---- shell script > ># if [ `/net/u/12/b/br/unet/a.out` > 0 ] > >if [ `/net/u/12/b/br/unet/a.out` > /dev/null ] > The people in comp.unix.shell will probably tell you that this line is > wrong. > dave > -- > Dave Vandervies dj3vande at eskimo dot com > Their failure is not your excuse; time to find an unaverage pub. > --Richard Bos in the scary devil monastery |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
dbr@kbrx.com wrote:
> Thanks Jojo - I'll give that a try. Do you know what .h file contains > the definitions for EXIT_xxx? > a quick grep would show... but it should be stdlib.h Bye, Jojo |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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> |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
"Joachim Schmitz" <nospam.jojo@schmitz-digital.de> writes:
> dbr@kbrx.com wrote: >> Thanks Jojo - I'll give that a try. Do you know what .h file contains >> the definitions for EXIT_xxx? >> > a quick grep would show... > > but it should be stdlib.h A quick grep could easily show something irrelevant like, say, a C++ "cstdlib" header, or some other system header from which <stdlib.h> gets the EXIT_SUCCESS and EXIT_FAILURE definitions, and which might not exist on another platform. <stdlib.h> is the right header to include in your program. (The documentation for the exit() function or a good C reference should tell you this.) -- Keith Thompson (The_Other_Keith) <kst-u@mib.org> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
![]() |
| Outils de la discussion | |
|
|