home *** CD-ROM | disk | FTP | other *** search
- From: maart@cs.vu.nl (Maarten Litmaath)
- Newsgroups: comp.unix.questions,alt.sources
- Subject: Re: UNIX path expansion
- Message-ID: <6360@star.cs.vu.nl>
- Date: 24 Apr 90 02:18:25 GMT
-
- In article <868@haydn.nsc.com>,
- mcdan@dtg.nsc.com (Eric McDaniel) writes:
- )Does anybody out there have any code that will accept
- )a path (of the form ". ~ /usr/local" etc.) and a series
- )of filenames with possible wildcards ("foo* .cshrc" etc.)
- )and will print out the files that match in each pathname
- )component?
- )...
-
- The following is a start; tilde expansion must be handled by the
- application invoking it (e.g. the login shell).
-
- : This is a shar archive. Extract with sh, not csh.
- : This archive ends with exit, so do not worry about trailing junk.
- : --------------------------- cut here --------------------------
- PATH=/bin:/usr/bin:/usr/ucb
- echo Extracting 'wot'
- sed 's/^X//' > 'wot' << '+ END-OF-FILE ''wot'
- X#!/bin/sh
- X# @(#)wot 1.0 90/04/01 Maarten Litmaath
- X# wot [-d dir_1 ... dir_N -f] pattern_1 ... pattern_N
- X# for each given directory (default the PATH is used) print the (possibly
- X# empty) list of files matching a given pattern
- X# we can't use find(1), as on many systems it doesn't have a -prune option
- X
- Xcase $1 in
- X-d)
- X dirs=
- X while shift
- X do
- X case $1 in
- X -f)
- X shift
- X break
- X esac
- X dirs="$dirs$1:"
- X done
- X ;;
- X*)
- X dirs="$PATH:"
- Xesac
- X
- XSED='
- X s/:$//
- X s/^:/.:/
- X s/:$/:./
- X : L
- X s/::/:.:/g
- X t L
- X s/$/:/
- X s-:-/:-g
- X s-///*-/-g
- X s/:/ /g
- X'
- X
- Xfor dir in `echo "$dirs" | sed "$SED"`
- Xdo
- X for pattern
- X do
- X (
- X eval set "$dir$pattern"
- X test -f "$1" -o -d "$1" &&
- X for i
- X do
- X echo "$i"
- X done
- X )
- X done
- Xdone
- + END-OF-FILE wot
- chmod 'u=rwx,g=rx,o=rx' 'wot'
- set `wc -c 'wot'`
- count=$1
- case $count in
- 711) :;;
- *) echo 'Bad character count in ''wot' >&2
- echo 'Count should be 711' >&2
- esac
- exit 0
- --
- 1) Alias must go as well. |Maarten Litmaath @ VU Amsterdam:
- 2) Sleep(3) should be sleep(2) again.|maart@cs.vu.nl, uunet!mcsun!botter!maart
-