Advertisement
mosaid

Untitled

Jan 5th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.59 KB | None | 0 0
  1. function cpfile() {
  2.     sourcefile="$1"
  3.     destinationDir="$2"
  4.     filename=$( basename "$sourcefile" )
  5.     extension="${filename##*.}"
  6.     filename="${filename%.*}"
  7.     alreadyExist=0
  8.     if [ -f "$destinationDir/$filename.$extension" ]   # file exist in destination
  9.         then
  10.                 filename=$( printf "%s_new.%s" "$filename" "$extension" )
  11.             alreadyExist=1
  12.         else
  13.             filename="$filename.$extension"
  14.     fi
  15.     if [[ "$3" == "--move" ]]
  16.         then  mv "$sourcefile"  "$destinationDir/$filename"
  17.         else  
  18.             if (( "$alreadyExist" == 0 )) ; then
  19.                 cp "$sourcefile"  "$destinationDir/$filename"
  20.             fi
  21.     fi
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement