title: SH script to move files from one dir to another depending on the filename
body: <p>I am trying to write a sh script that will run when one of my downloads is completed.<br></p>
  
  <p>It should look for a specific filename on ~/Downloads and move it to a different dir depending on the filename.<br></p>
  
  <p>I.e. I have downloaded the last episode of Glee, the filename is:</p>
  
  <pre><code>glee_some_trash_files_always_have.mkv
  </code></pre>
  
  <p>It should be moved to </p>
  
  <pre><code>~/TVshows/Glee/
  </code></pre>
  
  <p>This is what I was able to do:</p>
  
  <pre><code>#!/bin/bash
  
  if filename in ~/Downoads; then
  result=
  if filename = *glee*; then
  result= mv $filename ~/TVshows/Glee/
  else
  if filename = *pokemon*; then
  result= mv $filename ~/TVshows/pokemon/
  endif
  done
  </code></pre>
  
  <p>Is my approach correct? Please note I am very new to sh.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>###############################################################################
  </code></pre>
  
  <p>Edit: Here is my script, I hope someone else could find it useful:</p>
  
  <pre><code>#!/bin/bash
  
  cd "$HOME/Downloads"
  # for filename in *; do
  find . -type f | while IFS= read filename; do # Look for files in all ~/Download sub-dirs
    case "${filename,,*}" in  # this syntax emits the value in lowercase: ${var,,*}  (bash version 4)
       *.part) : ;; # Excludes *.part files from being moved
       move.sh) : ;;
  #    *test*)            mv "$filename" "$HOME/TVshows/Glee/" ;; # Using move there is no need to {&amp;&amp; rm "$filename"}
       *test*)           scp "$filename" "imac@imac.local:/users/imac/Desktop/" &amp;&amp; rm "$filename" ;;
       *american*dad*)   scp "$filename" "imac@imac.local:/users/imac/Movies/Series/American\ Dad/" &amp;&amp; rm "$filename" ;;
       *) echo "Don't know where to put $filename" ;;
    esac
  done
  </code></pre>