Yet Another bourne shell query
Don Bolton
lugnut at sequent.UUCP
Wed Sep 5 11:28:22 AEST 1990
In article <437 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
>Hey, wow!, a special group for all my dumb shell questions! And I just
>happen to have one to ask...
>
>
>Recently, I've had the fun of modifying programs so they can be started
>by init and/or inetd, and still work. These daemons, unlike shells,
>have a way of starting programs with very little initialization. On
>some of my recent portability tests, I have even come across one Unix
>system whose init starts things with an empty environ vector (i.e.,
>environ[0] == (char *)0), and with NO open files. Yes, you read that
>right; files 0, 1 and 2 are not open. It does at least make argv[0]
>contain a pointer to the program's name, and argc is correct, so I
>guess I really shouldn't complain.
>
>But this causes interesting problems when the "program" is a shell
>script. In C, I know how to call fstat() and test the result for
>zero. In Bourne Shell, I don't know how to do the equivalent. I
>basically want to write something like:
> if [ <file 0 is open> ];then exec</dev/null;fi
>but I don't know what to put between the [ and the ]. Any ideas?
>Is it possible? Or should I just rewrite the scripts in C?
I'm one of them thar marketeer types gone bad turned programmer, so
I have some trouble relating to your meaning of "open"
but test operators are...
-b file file is a special block file
-c file file is a special character file
-d file file is a directory
-f file file is an ordinary file
-g file file has its set group id (SGID) bit set
-k file file has its sticky bit set
-p file file is a named pipe
-r file file is readable by the process < this whatcha need ?
-s file file is nonzero length
-t fd fd is the open file descriptor associated with a terminal
(1 is default)
-u file file has its user id (SUID) bit set
-w file file is writeable by the process
-x file file is executable
I reccomend the book UNIX SHELL PROGRAMMING Kochan and Wood
one o them thar Hayden Books. and The UNIX Programming Environment
by Kernighan and Pike, Prentice Hall. Twixt the two I've written some
hairy programs. also the AWK Programming Language by Aho, Weinberger,
Kernighan looks like it would be of help to you.
More information about the Comp.unix.shell
mailing list