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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:33:59+00:00 2026-06-04T15:33:59+00:00

This script needs to run on Mac OSX. The following script is to build

  • 0

This script needs to run on Mac OSX. The following script is to build a QT QRC (resource file definition) which is nothing more than an XML file with a different extension. I’ve tested each piece of the script isolated in terminal on the mac. All is as it should work, but I can’t get the for loop to execute properly.

This script should:

  1. List all files in the current directory
  2. Strip out the ./ produced by the find
  3. Create the proper XML

Here’s what the result should look like:

<RCC>
    <qresource prefix="/">
        <file>login.html</file>
        <file>start.html</file>
        <file>base/files.html</file>
    </qresource>
</RCC>

Here’s my current script:

 #!/bin/bash
    #Define the File
        file="Resources.qrc"
    #Clear out the old file, we want a fresh one
        rm $file
    #Format the start of the QRC file
        echo "<RCC>" >> $file
        echo "  <qresource prefix=\"/\">" >> $file
        #Iterate through the directory structure recursively
            for f in $(find . -type f)
                do
                    #Ensure the file isn't one we want to ignore
                        if [[ $f != "*.qrc" && $f != "*.rc" && $f != "*.h" && $f != "*.sh" ]]
                        then
                            #Strip out the ./ for the proper QRC reference
                                echo "<file>$f</file>" | sed "s/.\///" >> $file
                        fi
                done
    #Close the QRC file up
        echo "  </qresource>" >> $file
        echo "</RCC>" >> $file

And this is what terminal keeps telling me:

'build-qrc.sh: line 11: syntax error near unexpected token `do
'build-qrc.sh: line 11: `           do

Any time I try to do a shell for loop it give me the same error. I’ve tried semi-colns and the like to no avail. Any ideas? Thanks.


Here’s the finalized script thanks to chepner. It generates a perfect QRC resource file for QT for use with embedding html items into a webkit driven app.

#!/bin/bash
#Define the Resource File
file="AncestorSyncUIPlugin.qrc"
#Clear out the old file if it exists, we want a fresh one
if [ -f $file ] 
then
    rm $file
fi
# Use the -regex primary of find match files with the following
# extensions: qrc rc sh h. Use -not to negate that, so only files
# that don't match are returned. The -E flag is required for
# the regex to work properly. The list of files is stored in
# an array
target_files=( $(find -E . -type f -regex ".*\.(png|jpg|gif|css|html)$") )

# Use a compound statement to redirect the output from all the `echo`
# statements at once to the target file. No need to remove the old file,
# no need to append repeatedly.
{
    #Format the start of the QRC file
    echo "<RCC>"

    # Use single quotes to avoid the need to escape the " characters
    echo '  <qresource prefix="/">'

    # Iterate over the list of matched files
    for f in "${target_files[@]}"
    do
        # Use parameter expansion to strip "./" from the beginning
        # of each file
        echo "  <file>${f#./}</file>"
    done
    #Close the QRC file up
    echo "  </qresource>"
    echo "</RCC>"
} > $file
  • 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-04T15:34:00+00:00Added an answer on June 4, 2026 at 3:34 pm

    I don’t see any syntax errors, but $f != "*.qrc" shouldn’t work the way you intend it. That tests the value of f against the literal string *.qrc. Here’s your script, shortened using various tricks:

    #!/bin/bash
    #Define the File
    file="Resources.qrc"
    # Use the -regex primary of find match files with the following
    # extensions: qrc rc sh h. Use -not to negate that, so only files
    # that don't match are returned. The -E flag is required for
    # the regex to work properly. The list of files is stored in
    # an array
    target_files=( $(find -E . -type f -not -regex ".*\.(q?rc|s?h)$") )
    
    # Use a compound statement to redirect the output from all the `echo`
    # statements at once to the target file. No need to remove the old file,
    # no need to append repeatedly.
    {
        #Format the start of the QRC file
        echo "<RCC>"
    
        # Use single quotes to avoid the need to escape the " characters
        echo '  <qresource prefix="/">'
    
        # Iterate over the list of matched files
        for f in "${target_files[@]}"
        do
            # Use parameter expansion to strip "./" from the beginning
            # of each file
            echo "    <file>${f#./}</file>"
        done
        #Close the QRC file up
        echo "  </qresource>"
        echo "</RCC>"
    } > $file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Powershell script that needs to be run automatically daily. This
I really need some quick tips here. I've got this VBScript script which sends
I'm working on a python script that needs to run between two given times.
I'm trying to write a python script that packages our software. This script needs
I have a php script that needs to run once every 5 minutes. Currently
I am working on a script that needs to run a perl script via
tl;dr Trying to run a service which needs ruby to run. But, Ruby is
I've got a Perl script that needs to execute another Perl script. This second
I have a PHP script with infinite loop. I need this script running forever.
I have this script that works, but I need to change the format of

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.