hemenway@cdp.UUCP (10/30/88)
I have been porting some scripts from the System V sh to the 4.3bsd sh and have some problems. Any ideas/explanations would be appreciated. 1. I/O redirection problem: : exec 2> /dev/null echo This message goes to /dev/null as it should. 1>&2 xxabcxx # error message should go to /dev/null--it doesn't < xxabcxx # error message should go to /dev/null--it doesn't The above script sends sh error messages to /dev/null only when stderr is redirected to /dev/null from the command line that called the script. 2. Problem with test -w: When I use the -w primitive with test to test a directory, it reports that the directory is not writeable, regardless of whether it is. The -r primitive works fine with directories. : # if $1 is a directory, this segment reports that $1 is not # writeable, regardless of whether it is if [ -w "$1" ] then echo "write perm" else echo "no write perm" fi Kathy Hemenway {uunet,ucbvax!hplabs}!cdp!sobell!kathy
chris@mimsy.UUCP (Chris Torek) (10/30/88)
In article <67700005@cdp> hemenway@cdp.UUCP writes: > exec 2> /dev/null > echo This message goes to /dev/null as it should. 1>&2 > xxabcxx # error message should go to /dev/null--it doesn't >The above script sends sh error messages to /dev/null only when stderr is >redirected to /dev/null from the command line that called the script. As far as I know, this is how things are supposed to work. >2. Problem with test -w: `test' is not built in to the 4BSD /bin/sh. /bin/test uses open() to test files; open for write fails on directories. SV sh apparently uses access(). To test directories you have to write your own test program. What does POSIX say about each of these? -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
gwyn@smoke.BRL.MIL (Doug Gwyn ) (10/31/88)
In article <14247@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: -In article <67700005@cdp> hemenway@cdp.UUCP writes: -> exec 2> /dev/null -> echo This message goes to /dev/null as it should. 1>&2 -> xxabcxx # error message should go to /dev/null--it doesn't ->The above script sends sh error messages to /dev/null only when stderr is ->redirected to /dev/null from the command line that called the script. -As far as I know, this is how things are supposed to work. No, it should work as Kathy expected. -What does POSIX say about each of these? It's not standardized yet. One hopes that 1003.2 won't canonicalize the zillions of bugs in older Bourne shells! My advice to Kathy is (assuming she has an SVR2 or later source license) to get the BRL Bourne shell and install it (properly configured, of course) in place of /bin/sh.
friedl@vsi.COM (Stephen J. Friedl) (10/31/88)
In article <14247@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > > `test' is not built in to the 4BSD /bin/sh. /bin/test uses open() to > test files; open for write fails on directories. SV sh apparently > uses access(). To test directories you have to write your own test > program. System V Release 3 fixed this problem; test(1) -- a builtin -- no longer uses access(2). Now if they would only make the $PATH search mechanism work the same way :-(. Steve -- Steve Friedl V-Systems, Inc. +1 714 545 6442 3B2-kind-of-guy friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl ----Nancy Reagan on 120MB SCSI cartridge tape: "Just say *now*"----