【问题标题】:Error in shell scriptshell 脚本中的错误
【发布时间】:2012-06-06 15:08:13
【问题描述】:

我正在使用一个 shell 脚本来帮助我解析库路径,以便我可以发送我的应用程序包。我对 shell 脚本了解不多,并且正在从其他部分中破解一些东西,所以我真的不知道如何解决这个问题。问题围绕着done << ...

这里有一些代码!请注意,这是基于 Qt 项目。

echo "Below is the list of install_name_tools that need to be added:"
while IFS= read -r -d '' file; do
    baseName=`basename "$file"`
    #echo "otool -L \"$file\" | grep -e \"*$baseName\""
    hasUsrLocal=`otool -L "$file" | grep -v -e "*$baseName" | grep -v libgcc_s.1.dylib | grep -v libstdc++.6.dylib | grep "/usr/local\|/Users"`
    if [ -n "$hasUsrLocal" ]; then
        #echo "WARNING: $file has /usr/local dependencies"
        #echo "\"$hasUsrLocal\""

        #echo "To Fix:"

        while read line; do
            #Remove extra info
            library=`echo "$line" | perl -pe 's/(.*?)\s\(compatibility version.*/\1/'`
            libraryBaseName=`basename "$library"`
            frameworkNameBase="$libraryBaseName.framework"
            isframework=`echo "$library" | grep "$frameworkNameBase"`

            unset fixCommand;
            if [ -n "$isframework" ]; then
                #Print out how to fix the framework
                frameworkName=`echo $library | perl -pe "s/.*?($frameworkNameBase\/.+)/\1/"`
                fixCommand=`echo "install_name_tool -change \"$library\" \"@executable_path/../Frameworks/$frameworkName\" \"$file\""`
            else
                #Print out how to fix the regular dylib
                if [ "$baseName" != "$libraryBaseName" ]; then
                    fixCommand=`echo "install_name_tool -change \"$library\" \"@executable_path/../Frameworks/$libraryBaseName\" \"$file\""`
                fi
            fi

            echo "$fixCommand"
        done << (echo "$hasUsrLocal")
        #echo "---------------------------------------------------------"
    fi

done << (find MyProgram.app -type f -print0)

这个打印的错误是指done &lt;&lt; (echo "$hasUsrLocal")这一行

./deploy.sh: line 563: syntax error near unexpected token `('
./deploy.sh: line 563: `        done << (echo "$hasUsrLocal")'

如果我注释掉一些脚本,done &lt;&lt; (find MyProgram.app -type f -print0) 也会遇到类似的问题。谢谢!

【问题讨论】:

    标签: qt shell install-name-tool


    【解决方案1】:

    我相信作者打算使用流程替换:

    done < <( find ...
    

    您也可以尝试将 find 传递到 while 循环中:

    find MyProgram ... | while IFS= read -r -d '' file; do ... done
    

    【讨论】:

    • 谢谢,这有助于我在谷歌上搜索修复!
    【解决方案2】:

    我修好了!感谢 William Pursell 提出的关键字“过程替换”。这让我有了“谷歌”的基础。

    我注意到这是一个间距问题。例如,需要像done &lt; &lt;(echo "$hasUsrLocal") 一样间隔!

    【讨论】:

      【解决方案3】:

      回答

      &lt;&lt; 符号用于此处的文档。您可能想要的是重定向进程替换:

      < <( : )
      

      &lt;(command_list) 构造用于process substitution,而第一个小于符号将循环的标准输入重定向到由紧随其后的进程替换创建的文件描述符。

      专业提示

      这是一种方便但令人困惑的语法。从右到左阅读真的很有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-10
        • 2017-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多