bourne and korn shell incompatibilities

David Elliott dce at mips.COM
Tue Feb 2 02:43:39 AEST 1988


In article <391 at dplace.UUCP> djl at dplace.UUCP (Dave Lampe) writes:
>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.

Very true.  "Undocumented features", whether they are bugs or true
features without documentation (like the old string operations in
BSD expr) should not be expected to work.

>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.

The following will also work, and it only uses builtin functions[*], so
there is no fork cost:


	case "`echo *.c`" in
		'*.c')
			echo "no files"
			;;
		*)
			echo "files found"
			;;
	esac

[*] In BSD sh, echo is not a builtin.  Then again, it doesn't have test ([),
either, so the above still beats the ls/tail method by 2 forks.

-- 
David Elliott		dce at mips.com  or  {ames,prls,pyramid,decwrl}!mips!dce



More information about the Comp.unix.questions mailing list