このスクリプトは Mac OSX で実行する必要があります。次のスクリプトは、異なる拡張子を持つ XML ファイルにすぎない QT QRC (リソース ファイル定義) を構築するためのものです。Mac のターミナルで分離されたスクリプトの各部分をテストしました。すべてが正常に機能するはずですが、for ループを適切に実行できません。
このスクリプトは次のことを行う必要があります。
- 現在のディレクトリ内のすべてのファイルを一覧表示する
- find によって生成された ./ を取り除きます
- 適切な XML を作成する
結果は次のようになります。
<RCC>
    <qresource prefix="/">
        <file>login.html</file>
        <file>start.html</file>
        <file>base/files.html</file>
    </qresource>
</RCC>
これが私の現在のスクリプトです:
 #!/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
そして、これは端末が私に言い続けることです:
'build-qrc.sh: line 11: syntax error near unexpected token `do
'build-qrc.sh: line 11: `           do
シェル for ループを実行しようとすると、同じエラーが発生します。私はセミコロンなどを試してみましたが、役に立ちませんでした。何か案は?ありがとう。
これがchepnerのおかげで完成したスクリプトです。html アイテムを webkit 駆動型アプリに埋め込む際に使用する、QT 用の完全な QRC リソース ファイルを生成します。
#!/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