[net.sources.bugs] "nmkdir" in the Bourne shell

ado@elsie.UUCP (Arthur David Olson) (09/03/85)

In article <1090@noscvax.UUCP>, broman@noscvax.UUCP (Vincent P. Broman) writes:
> After seeing Bourne shell and C language versions of a program
> to create sub-sub-sub directories, it seemed to me that the Cshell
> offered the simplest quick implementation, one that only creates
> ONE subprocess. It suffices to let mkdir produce all diagnostics.

Note that the script that followed in the referenced article handles a command
such as
	nmkdir a/b/c a/b/d
differently than do the programs it sought to emulate:
	Script started on Mon Sep  2 16:36:30 1985
	Warning: no access to tty; thus no job control in this shell...
	% cd /tmp
	% rm -f -r a
	% nmkdir.sh a/b/c a/b/d
	% rm -f -r a
	% nmkdir.csh a/b/c a/b/d
	mkdir: cannot make directory a
	mkdir: cannot make directory a/b
	% 
	script done on Mon Sep  2 16:37:08 1985

And I suppose I'm obliged to reveal my entry in the contest (with no warranty
as to suitability for any purpose whatsoever).  The "set x" and "shift" nonsense
gets around the odd handling of "$@" by sh when $# is zero:
	for i
	do
		case "$i" in
			/*)	tonow=/ ;;
			*)	tonow= ;;
		esac
		set x
		IFS=/
		for j in $i
		do
			IFS=" "
			tonow="$tonow$j"
			test -d "$tonow" || set "$@" "$tonow"
			tonow="$tonow/"
		done
		IFS=" "
		case $# in
			1)	;;
			*)	shift ; /bin/mkdir "$@" || exit $?
		esac
	done
--
Bugs is a Warner Brothers trademark.
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks