bourne and korn shell incompatibilities

Wolf Paul wnp at killer.UUCP
Tue Feb 2 07:51:14 AEST 1988


In article <674 at pttesac.UUCP} vanam at pttesac.UUCP (Marnix van Ammers) writes:
}
}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
}      echo "There's a C file in the current directory."
}    else
}      echo "There are no C files in the current directory."
}    fi
}
}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.
}
}Does anyone have any recommendations as to the best way to
}make these scripts palatable to the korn shell?

Try this one:


STRING=`echo *.c`
if [  "$STRING" != "*.c" ] ; then
	echo "There is a C program in this dir"
else
	echo "there is NO C program in this dir"
fi

I tried it both under /bin/sh and /bin/ksh and it works identically.

Wolf Paul
ihnp4!killer!wnp
ihnp4!killer!dcs!wnp



More information about the Comp.unix.questions mailing list