How to issue a C SHELL command within a C program

Guy Harris guy at auspex.auspex.com
Sun Sep 2 11:30:54 AEST 1990


>Incidentally, while /bin/sh should always be used to execute commands
>from a program, when you spawn an interactive subshell you should use
>the valuse of the SHELL environment variable.

This should also be done if running a *user-supplied* command.

Some examples of the rules:

1) if your program is, say, running an "rm -rf" on some directory to
   remove it, it should use "system()" and do it from "/bin/sh".  The
   program knows what behavior it wants from that command, and doesn't
   want the user's preferences getting in its way.

2) if the user typed "!" or whatever the "escape to shell" command is,
   it should use whatever shell SHELL specifies.

3) if the user typed "!egrep mmedea /etc/passwd" or something like that,
   i.e. a shell escape to run one command, it should use whatever shell
   SHELL specifies.

4) if the user is telling the program to run some command and grab input
   from it, or send output to it (for instance, running a region of a
   file through a filter in an editor), it should use whatever shell
   SHELL specifies.

etc..



More information about the Comp.unix.questions mailing list