Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6867161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:29+00:00 2026-05-27T03:16:29+00:00

I’m trying to build a BASH script on OS X (10.6/10.7) to process a

  • 0

I’m trying to build a BASH script on OS X (10.6/10.7) to process a folder called QCExports which has folders with people’s names in it in the format “LAST, First”, i.e. “BOND, James”.

When I run the following script, everything works but it falls over on folder or filenames with a space in them.

Script Code:

#!/bin/bash
echo "QuickCeph Export Script"

#Set Path to Process & Paths to Copy To
pathToQCExports=/Users/myuser/Desktop/QCExports
sureSmilePath=/Users/myuser/Desktop/QCExportsForSureSmile
sesamePath=/Users/myuser/Desktop/QCExportsForSesame
blankReplace=""

#Process Each Name
find $pathToQCExports -type d | while read name ; do

    #escaping the folder with a space in the name
nameParsed=${name/", "/",\ "}

    echo "Processing: "$nameParsed  
    pathSureSmile=${nameParsed/$pathToQCExports/$sureSmilePath}
    pathSesame=${nameParsed/$pathToQCExports/$sesamePath}
    mkdir $pathSesame
    mkdir $pathSureSmile

    echo "Folders Created"

    #Copy For SureSmile 
    echo ${pathSureSmile}"/Suresmile-Frontal\ Photo.jpg" ${pathSureSmile}"/Suresmile-Frontal\ Photo.jpg"
    #cp `${$pathSureSmile}"/Suresmile-Frontal\ Photo.jpg" ${pathSureSmile}"/Suresmile-Frontal\ Photo.jpg"`

    #Copy For Sesame
    echo ${pathSesame}"/Suresmile-Frontal\ Photo.jpg" ${pathSesame}"/S02.jpg"
    #cp `${pathSesame}"/Suresmile-Frontal\ Photo.jpg" ${pathSesame}"/S02.jpg"`

done

echo "Completed";

Output:

QuickCeph Export Script
Processing: /Users/myuser/Desktop/QCExports/BOND,\ James
mkdir /Users/myuser/Desktop/QCExportsForSesame/BOND,\ James
mkdir: James: File exists
mkdir /Users/myuser/Desktop/QCExportsForSureSmile/BOND,\ James
mkdir: James: File exists
Folders Created
/Users/myuser/Desktop/QCExportsForSureSmile/BOND,\ James/Suresmile-Frontal\ Photo.jpg /Users/myuser/Desktop/QCExportsForSureSmile/BOND,\ James/Suresmile-Frontal\ Photo.jpg
/Users/myuser/Desktop/QCExportsForSesame/BOND,\ James/Suresmile-Frontal\ Photo.jpg /Users/myuser/Desktop/QCExportsForSesame/BOND,\ James/S02.jpg
Completed

On OS X usually in the terminal, you use a \ to escape a space in a folder or filename, but that doesn’t seem to work.

I notice that it’s interpreting the spaces as a normal space would be interpreted on the command line and thinking I want to execute the command on two files – i.e. it’s not passing the \ onwards. I end up with a folder called “Bond,\” and a folder called “James” in the folder I execute the script from.

Note, I deliberately have the cp commands # out at the moment, so they aren’t being executed… the problem is the same for both creating the folders & copying the filenames.

If I copy and paste the “echo’d” version of these commands into a terminal window, the commands work! But when BASH executes them, it doesn’t respect the . 🙁

Any ideas?

Thanks!!
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:16:30+00:00Added an answer on May 27, 2026 at 3:16 am

    See my modifications on your script, you don’t have to substitute spaces like you tried.
    Moreover, you must choose if you backslash the spaces or if you are using quotes.
    The simple way is to use double quotes.
    Good doc about quotes, see http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words

    #!/bin/bash
    echo "QuickCeph Export Script"
    
    #Set Path to Process & Paths to Copy To
    pathToQCExports=/Users/myuser/Desktop/QCExports
    sureSmilePath=/Users/myuser/Desktop/QCExportsForSureSmile
    sesamePath=/Users/myuser/Desktop/QCExportsForSesame
    blankReplace=""
    
    #Process Each Name
    find $pathToQCExports -type d | while read nameParsed ; do
    
        echo "Processing: $nameParsed"
        pathSureSmile="${nameParsed/$pathToQCExports/$sureSmilePath}"
        pathSesame="${nameParsed/$pathToQCExports/$sesamePath}"
        mkdir "$pathSesame"
        mkdir "$pathSureSmile"
    
        echo "Folders Created"
    
        #Copy For SureSmile 
        echo "${pathSureSmile}/Suresmile-Frontal Photo.jpg" "${pathSureSmile}/Suresmile-Frontal Photo.jpg"
    
        #Copy For Sesame
        echo "${pathSesame}/Suresmile-Frontal Photo.jpg" "${pathSesame}/S02.jpg"
    
    done
    
    echo "Completed"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.