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 8547819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:21:04+00:00 2026-06-11T13:21:04+00:00

I’ve got a simple script: #!/bin/sh cd /tmp/pics for pic in *.jpg; do php

  • 0

I’ve got a simple script:

#!/bin/sh
cd /tmp/pics
for pic in *.jpg;
do
  php -f /tmp/pics/covert.php $pic;
done

When my pictures have white-space in their names that script won’t work. How could I fix that?

How can I fix my script to handle whitespace properly, and also handle other JPEG extensions, such as “JPG”, “JPEG”, “jpeg”?

  • 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-06-11T13:21:05+00:00Added an answer on June 11, 2026 at 1:21 pm

    Quoting rules in bash and other shells are unlike those in “normal” scripting languages like Ruby and Python and Perl, so this may be confusing at first, but if you put double quotes around $pic, bash will treat the contents of the variable properly even if it contains spaces.

    That one fix would make your script look like this

    #!/bin/sh
    cd /tmp/pics
    for pic in *.jpg;
    do
      php -f /tmp/pics/covert.php "$pic";
    done
    

    I would also remove the semi-colons at the end of each line. Those are only needed if you’re cramming multiple lines together on one line. They’re not needed in bash the way they are in PHP or (to a lesser extent) JavaScript.

    As written, this is using the Bourne shell instead of bash. (For the moment we’ll ignore the fact that bash might be used on your system to emulate the Bourne shell.) Change the “shebang” line at the top if you want to use bash. Typically it is #!/bin/bash.

    To handle multiple file extensions, you can just stack them up next to each other with spaces in between, like this

    for pic in *.jpg *.jpeg *.JPEG *.JPG
    

    As Jens points out, you might have odd corner-cases where the file extension is mixed case. You can handle that with brackets to group characters

    for pic in *.[jJ][pP][gG] *.[jJ][pP][eE][gG]
    

    or you could use glenn’s approach of setting your shell options to ignore case (and non-matching patterns) and then use a simpler glob pattern

    shopt -s nocaseglob nullglob
    for pic in *.jpg *.jpeg
    

    If we take that latter approach, the final script would look like this:

    #!/bin/bash
    cd /tmp/pics
    shopt -s nocaseglob nullglob
    for pic in *.jpg *.jpeg
    do
      php -f /tmp/pics/covert.php "$pic"
    done
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

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.