Advertisement
metalx1000

Copy Files if getops is true

May 25th, 2015
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. folder="files"
  4. [ -a "$folder" ] && echo "$folder exists" || mkdir "$folder"
  5.  
  6. move(){
  7.   echo "Moving $1 for ${folder}..."
  8.   mv $1  "$folder"
  9. }
  10.  
  11. copy(){
  12.   echo "Copying $1 for ${folder}..."
  13.   cp $1 "$folder"
  14. }
  15.  
  16. while getopts ":f:" arg; do
  17.   case "$arg" in
  18.     f)
  19.       f="${OPTARG}"
  20.       ;;
  21.   esac
  22. done
  23.  
  24. for file in *
  25. do
  26.   if [ "$f" = "true" ]
  27.   then
  28.     move "$file"
  29.   else
  30.     copy "$file"
  31.   fi
  32. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement