mkdirhier.sh 912 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # $XConsortium: mkdirhier.sh,v 1.6 91/08/13 18:13:04 rws Exp $
  3. # Courtesy of Paul Eggert
  4. newline='
  5. '
  6. IFS=$newline
  7. case ${1--} in
  8. -*) echo >&2 "mkdirhier: usage: mkdirhier directory ..."; exit 1
  9. esac
  10. status=
  11. for directory
  12. do
  13. case $directory in
  14. '')
  15. echo >&2 "mkdirhier: empty directory name"
  16. status=1
  17. continue;;
  18. *"$newline"*)
  19. echo >&2 "mkdirhier: directory name contains a newline: \`\`$directory''"
  20. status=1
  21. continue;;
  22. ///*) prefix=/;; # See Posix 2.3 "path".
  23. //*) prefix=//;;
  24. /*) prefix=/;;
  25. -*) prefix=./;;
  26. *) prefix=
  27. esac
  28. IFS=/
  29. set x $directory
  30. IFS=$newline
  31. shift
  32. for filename
  33. do
  34. path=$prefix$filename
  35. prefix=$path/
  36. shift
  37. test -d "$path" || {
  38. paths=$path
  39. for filename
  40. do
  41. if [ "$filename" != "." ]; then
  42. path=$path/$filename
  43. paths=$paths$newline$path
  44. fi
  45. done
  46. mkdir $paths || status=$?
  47. break
  48. }
  49. done
  50. done
  51. exit $status