How to issue a C SHELL command within a C program

Guy Harris guy at auspex.auspex.com
Thu Aug 30 08:26:59 AEST 1990


>	if (!sh)
>#if BSD || SUN
>		sh = "/bin/csh";
>#endif /* BSD || SUN */
>#if USG || SMOS || HPUX || XENIX
>		sh = "/bin/sh";
>#endif /* USG || SMOS || HPUX || XENIX */

This isn't really necessary.  Some of the systems in the latter category
*do* have the C shell, and some of the users in systems in the former
category don't use it if they have an alternative they like better.  In
addition, most UNIX systems these days arrange for the SHELL environment
variable to be set.  Just doing

	if (!sh)
		sh = "/bin/sh";

shouldn't annoy any C shell users, and removes some ugly #ifdefs.  (BTW,
even on BSD and SunOS systems, if the user's "/etc/passwd" entry doesn't
specify a shell, they get "/bin/sh", not "/bin/csh".)

>#if USG || SMOS || HPUX || XENIX
>	/* Parent disables signals and waits. */
>	oldsigint = signal(SIGINT, SIG_IGN);
>	oldsigquit = signal(SIGQUIT, SIG_IGN);
>	wait(&status);
>	signal(SIGINT, oldsigint);
>	signal(SIGQUIT, oldsigquit);
>#else /* BSD || SUN */
>	/* BSD should disable signals while waiting for child too,  */
>	/* but I can't remember how. -- RLD 08-28-90		    */
>	wait(&status);
>#endif /* USG || SMOS || HPUX || XENIX */

BSD does it exactly the same way the other systems do.

On BSD and SunOS systems - and on some systems that fall into the first
category - you can block, rather than ignore, the signal, so that if the
user types ^C it'll be "held" until they unblock it.

If you don't want to do that, though, the same calls to "signal()" you
use for the other systems will do the job on BSD and SunOS. 



More information about the Comp.unix.questions mailing list