RandomGuy32

s08.sh

May 29th, 2019
125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. if [ "$#" -lt 2 ]
  4. then
  5.     echo "Not enough arguments. Must be exactly 2."
  6. else
  7.     if [ "$#" -gt 2 ]
  8.     then
  9.         echo "Too many arguments. Must be exactly 2."
  10.     else       
  11.         topname=$1
  12.        
  13.         while [ -d "$topname" ]
  14.         do
  15.             echo "Directory $topname already exists. Please enter a different name."
  16.             read newname
  17.             topname=$newname
  18.         done
  19.        
  20.         sudo mkdir "$topname"
  21.         sudo chmod a=rwx "$topname"
  22.         echo "Created directory $topname."
  23.        
  24.         for ((i=1;i<=$2;i++))
  25.         do
  26.             echo "Please enter a name for a subdirectory. ($i/$2)"
  27.             read subname
  28.             sudo mkdir "$topname/$subname"
  29.             sudo chmod a=rx "$topname/$subname"
  30.             echo "Created directory $topname/$subname."
  31.         done
  32.     fi
  33. fi
RAW Paste Data