1

我正在编写一个运行 Cheetah 的脚本;在某些时候,有一些 bash 命令,我得到一个语法错误(“Cheetah 为这个模板生成的 Python 代码错误”)。

涉及的线路是:

&& name=$(echo '\$another_variable'".phy" | cut -d _ -f 1)

语法错误出现在第一个“$”符号上。它昨天工作所以我有点困惑......

整个代码被包装在一个 xml 标签中:

<command><![CDATA[
    ln -s '$input' '$input.element_identifier' &&

    BlastAlign -i '$input.element_identifier'
    -m $advanced_option.m
    #if $advanced_option.r != ""
        -r $advanced_option.r
    #end if
    #if $advanced_option.x != ""
        -x $advanced_option.x
    #end if
    -n $advanced_option.n
    #if $advanced_option.s != 0
        -s $advanced_option.s
    #end if

    && mkdir outputs

    && name=$(echo '\$input.element_identifier'".phy" | cut -d _ -f 1)

    && number=$(grep '/' '\$input.element_identifier'".phy" | wc -l)

    && new_file=$name"_sp"$number".phy"
    && mv '\$input.element_identifier'".phy" '$new_file'
    && new_file2=$name"_sp"$number".nxs"
    && mv '\$input.element_identifier'".nxs" '$new_file2'
    && cp '$new_file' outputs/
    && cp '$new_file2' outputs/

    #if $fasta_out.value == True
        && python $__tool_directory__/scripts/S01_phylip2fasta.py /outputs/'$new_file' outputs/$name"_sp"$number".fasta"
    #end if

]]></command>
4

1 回答 1

1

您必须筛选(使用反斜杠转义)$要传递给 bash 的每个符号,否则Cheetah会尝试解释它们:

&& name=\$(echo '\$input.element_identifier'".phy" | cut -d _ -f 1)

&& number=\$(grep '/' '\$input.element_identifier'".phy" | wc -l)

等等

于 2017-10-27T19:10:19.113 回答