Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site tikal.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tikal!stan From: stan@tikal.UUCP (Stan Tazuma) Newsgroups: net.sources Subject: Re: "nmkdir" in the Bourne shell at a Unix machine near you. Message-ID: <226@tikal.UUCP> Date: Tue, 27-Aug-85 16:32:38 EDT Article-I.D.: tikal.226 Posted: Tue Aug 27 16:32:38 1985 Date-Received: Wed, 28-Aug-85 09:55:00 EDT References: <1052@sdcsvax.UUCP> <309@cxsea.UUCP> Reply-To: stan@tikal.UUCP (Stan Tazuma) Organization: Teltone Corp., Kirkland, WA Lines: 57 Summary: Organizatio: Teltone Corporation, Kirkland, WA In article <309@cxsea.UUCP> blm@cxsea.UUCP (Brian Matthews) writes: >> ** If you want it, it's yours. All I ask in return is that if you >> ** figure out how to do this in a Bourne Shell script you send me >> ** a copy. > >Here 'tis. It basically uses expr to hack apart the requested path, and >do mkdir's on all the intermediate components. I wrote it a while ago, >but haven't used it much, but I do think it works well. There are three >known problems: > > 1. It's slow. > 2. It doesn't trap any signals, so you can hit delete and have half > of a path made. This doesn't hurt anything, you may just have to > do a little cleaning up. > 3. It's slow. Just to illustrate some possibly little known features of the Bourne shell, I thought I'd followup with another version of nmkdir. Expr and test can be slow enough that the use of the shell pattern matching features (the case statement) may be preferred. Also, creative use of IFS can be a big help. Here is my version: #! /bin/sh cwd=`pwd` IFS=/ # after setting IFS, anything with '/' has to be quoted. # also, IFS will take care of repeated '/'s properly. for arg { case "$arg" { /*) cd "/" ;; } for d in $arg { if test ! -d $d then if mkdir $d then : fall through else echo "Error making directory $d in dirpath $arg" exit 1 #### break fi fi if cd $d then : ok, go on else echo "Error, can't chdir to $d in dirpath $arg" exit 1 fi } cd "$cwd" } exit