473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2138
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: brian.vincent | last post by:
I'm trying to use the ssh2 functions to run a graphical app. I have no problem opening ssh2_shell and running something like "/bin/ls /tmp". However when I try to do something like:...
2
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
1
by: rk | last post by:
Hi, I'm trying to write a cgi/perl programs to post a report like the following format in which the the user has to feed the values(nos) in the boxes under % Done Qual Rel. Stab P1 p2 P3.......
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
2
by: john wright | last post by:
Our company wants to standardize all our new programs. We are using .NET 2.0 and VB.NET against an Oracle Database and SQL Server Database. One suggestion was to have a single sign on and based...
1
by: Grzegorz ¦lusarek | last post by:
Hi everyone. I'm looking for javascript tools for web browser like IE and OPERA. I want find something like javascript shell http://www.squarefree.com/shell/shell.html for IE and OPERA. Does anyone...
13
by: Snis Pilbor | last post by:
Hello, Here is an idea I've been toying with to speed up programs but still keep them portable. It's just a very handwavey rough description right now since I haven't worked out details. The...
12
by: Steve Howell | last post by:
I've always thought that the best way to introduce new programmers to Python is to show them small code examples. When you go to the tutorial, though, you have to wade through quite a bit of...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: Programs dealing with autoruns Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list programs that help me to view/modify the autoruns...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.