bourne and korn shell incompatibilities
Dave Lampe
djl at dplace.UUCP
Mon Feb 1 03:44:12 AEST 1988
In article <674 at pttesac.UUCP> you write:
>
>Here's an incompatibility between ksh and sh. With ksh, this fails
>on both the UNIX-PC and the 3B20 if there's more than one *.c file.
>Works OK with the bourne shell.
> if [ -f *.c ];then
>Apparently the bourne shell permits a test such as
> if [ -f abc.c def.c xyz.c ]
>probably by throwing away the def.c and xyz.c . The korn
>shell calls it a syntax error and fails the test even if
>the first file exists.
>I realize that the bourne shell never advertised that multiple
>arguments were allowed, but it worked, I used it, ...
First this is not an undocumented feature, it is a bug in the test
builtin in sh. The documentation specificly says "-f file", the
second filename is indeed a syntax error since it is not a valid flag.
But to solve your problem, you will have to change
if [ -f *.c ]
to
if [ -f `ls *.c | tail -1` ]
That way test will only see 1 argument.
Dave Lampe
{ihnp4 | ames | lll-tis}!ptsfa!pacbell!dplace!djl
(415) 455-1571
More information about the Comp.unix.questions
mailing list