I am having a bit of bother with a control flow statement for a small interactive script I have which sorts and processes unsorted files from a desktop folder.

The script takes in a series of arguments through the command line

jpg gif docx

And then iterates through an unsorted folder pulling all types of that file to newly created desktop directories.

Its working great to a point, but the issue I have is, how to get the remaining file types (.wav png midi and a whole plethora of other types) in that unsorted folder automatically moved to a new miscellaneous folder that needs to be created when the original argument of jpg gif docx above is executed.

The part after done I can not get to run.

read -p "Good Morning, Please enter your file type name for sorting [ENTER]:" all_extensions
if cd /Users/christopherdorman/desktop
  then  while read extension
      do    destination="folder$extension"
        mkdir -p "$destination"
        mv  -v unsorted/*."$extension" "$destination"
      done   <<< "${all_extensions// /$'\n'}"
    if mv  -v unsorted/* "foldermisc"
      then  echo "Good News, the rest of Your files have been successfully processed"
  • why is this been edited – Syntax Killer Nov 26 '16 at 20:34
  • Is this the full script or just a part of it? – George Vasiliou Nov 26 '16 at 20:51
  • full script. .....It runs. its the bit after done which starts <<< I can not get the remaining file types done – Syntax Killer Nov 26 '16 at 21:02
  • It looks like you need to mkdir -p foldermisc before you try to mv there. – Nathan Wilson Nov 26 '16 at 22:41
  • @NathanWilson Can I just thank you for that. I have asked this question on numerous sites and no one has chirped in with the answer. that worked – Syntax Killer Nov 27 '16 at 7:47

It looks like you need to mkdir -p foldermisc before you try to mv there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.