1: # -*- perl -*- 2eval 'exec perl -wS $0 ${1+"$@"}' 3 if 0; 4# 5# mkdir - a perl script to substitute mkdir -p 6# accepts "/", ":", and "\" as delimiters of subdirectories 7# options -p (for compatibility) 8# -mode mode 9# 10# Copyright 2000, 2010 Oracle and/or its affiliates. 11 12use Cwd; 13 14$currdir = cwd; 15 16$MODE = 00777 ; 17 18while ( $#ARGV >= 0 ) { 19 if ( $ARGV[0] eq "-mode" ) { 20 $MODE = oct $ARGV[1] ; 21 shift @ARGV ; 22 shift @ARGV ; 23 } 24 elsif ( $ARGV[0] eq "-p" ) { 25 shift @ARGV ; 26 # -p does not do anything, it's supported just for compatibility 27 } 28 else { 29 30 $ARGV[0] =~ s?\\|:?/?g ; 31 @SUBDIRS = split "/", $ARGV[0] ; 32 33 # absolute path UNIX 34 if ( $SUBDIRS[0] eq "" ) { 35 chdir '/' ; 36 shift @SUBDIRS ; 37 } 38 # absolute path WINDOWS 39 if ( $#SUBDIRS > 1 ) { 40 if ( $SUBDIRS[1] eq "" ) { 41 if ( $SUBDIRS[0] =~ /\w/ ) { 42 chdir "$SUBDIRS[0]:\\" ; 43 shift @SUBDIRS ; 44 shift @SUBDIRS ; 45 } ; 46 } ; 47 } 48 49 while (@SUBDIRS) { 50 if ( -e $SUBDIRS[0] ) { 51 if ( ! -d $SUBDIRS[0] ) { 52 die "file exists\n" 53 } 54 } 55 else { 56 mkdir $SUBDIRS[0], $MODE or die "Can't create directory $SUBDIRS[0]" 57 } 58 chdir $SUBDIRS[0] or die "Can't cd to $SUBDIRS[0]" ; 59 shift @SUBDIRS ; 60 } ; 61 62 shift @ARGV ; 63 } ; 64 chdir $currdir; 65} 66