home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1225 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: maart@cs.vu.nl (Maarten Litmaath)
  2. Newsgroups: comp.unix.questions,alt.sources
  3. Subject: Re: UNIX path expansion
  4. Message-ID: <6360@star.cs.vu.nl>
  5. Date: 24 Apr 90 02:18:25 GMT
  6.  
  7. In article <868@haydn.nsc.com>,
  8.     mcdan@dtg.nsc.com (Eric McDaniel) writes:
  9. )Does anybody out there have any code that will accept
  10. )a path (of the form ". ~ /usr/local" etc.) and a series
  11. )of filenames with possible wildcards ("foo* .cshrc" etc.)
  12. )and will print out the files that match in each pathname
  13. )component?  
  14. )...
  15.  
  16. The following is a start; tilde expansion must be handled by the
  17. application invoking it (e.g. the login shell).
  18.  
  19. : This is a shar archive.  Extract with sh, not csh.
  20. : This archive ends with exit, so do not worry about trailing junk.
  21. : --------------------------- cut here --------------------------
  22. PATH=/bin:/usr/bin:/usr/ucb
  23. echo Extracting 'wot'
  24. sed 's/^X//' > 'wot' << '+ END-OF-FILE ''wot'
  25. X#!/bin/sh
  26. X# @(#)wot 1.0 90/04/01 Maarten Litmaath
  27. X# wot [-d dir_1 ... dir_N -f] pattern_1 ... pattern_N
  28. X# for each given directory (default the PATH is used) print the (possibly
  29. X# empty) list of files matching a given pattern
  30. X# we can't use find(1), as on many systems it doesn't have a -prune option
  31. X
  32. Xcase $1 in
  33. X-d)
  34. X    dirs=
  35. X    while shift
  36. X    do
  37. X        case $1 in
  38. X        -f)
  39. X            shift
  40. X            break
  41. X        esac
  42. X        dirs="$dirs$1:"
  43. X    done
  44. X    ;;
  45. X*)
  46. X    dirs="$PATH:"
  47. Xesac
  48. X
  49. XSED='
  50. X    s/:$//
  51. X    s/^:/.:/
  52. X    s/:$/:./
  53. X    : L
  54. X    s/::/:.:/g
  55. X    t L
  56. X    s/$/:/
  57. X    s-:-/:-g
  58. X    s-///*-/-g
  59. X    s/:/ /g
  60. X'
  61. X
  62. Xfor dir in `echo "$dirs" | sed "$SED"`
  63. Xdo
  64. X    for pattern
  65. X    do
  66. X        (
  67. X            eval set "$dir$pattern"
  68. X            test -f "$1" -o -d "$1" &&
  69. X                for i
  70. X                do
  71. X                    echo "$i"
  72. X                done
  73. X        )
  74. X    done
  75. Xdone
  76. + END-OF-FILE wot
  77. chmod 'u=rwx,g=rx,o=rx' 'wot'
  78. set `wc -c 'wot'`
  79. count=$1
  80. case $count in
  81. 711)    :;;
  82. *)    echo 'Bad character count in ''wot' >&2
  83.         echo 'Count should be 711' >&2
  84. esac
  85. exit 0
  86. --
  87.  1) Alias must go as well.            |Maarten Litmaath @ VU Amsterdam:
  88.  2) Sleep(3) should be sleep(2) again.|maart@cs.vu.nl, uunet!mcsun!botter!maart
  89.