bourne and korn shell incompatibilities

Lars Henrik Mathiesen thorinn at diku.dk
Thu Feb 4 20:18:44 AEST 1988


In article <10423 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <1450 at quacky.mips.COM> dce at mips.COM (David Elliott) writes:
>Actually, if you have exactly one file, called `*.c', this will
>claim there are no files.  To fix this you could use

>	case "`echo *.c`" in
>		"*.c")
>			if [ -f "*.c" ]; then
>				echo files found
>			else
>				echo no files
>			fi;;
>		*)
>			echo files found;;
>	esac

>although this seems like overkill, in general.

I just had to invent the same thing and came up with this:

	if (set *.c; exec test -f $1); then
		echo files found
	else
		echo no files
	fi

This works for 4.3BSD Bourne shell; on this system "test -f *.c" gives a
`too many arguments' error for two or more files! I don't see why it shouldn't
work with Korn shell.
  Note that this uses exactly one fork and one exec, and that it doesn't
clobber the arguments because the "set" is used in a subshell.
--
Lars Mathiesen, DIKU, U of Copenhagen, Denmark      [uunet!]mcvax!diku!thorinn
Institute of Datalogy -- we're scientists, not engineers.



More information about the Comp.unix.questions mailing list