I work on a script running Cheetah ; at some point there are some bash commands and I got a syntax error ("Error in the Python code which Cheetah generated for this template").
The line involved is :
&& name=$(echo '\$another_variable'".phy" | cut -d _ -f 1)
The syntax error being on the very first '$' sign. It worked yesterday so I'm kind of confused ...
The whole code is wrraped in a xml tag :
<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>
You have to screen (escape with a backslash) every $
sign that you want to pass to bash, else Cheetah
tries to interpret them:
&& name=\$(echo '\$input.element_identifier'".phy" | cut -d _ -f 1)
&& number=\$(grep '/' '\$input.element_identifier'".phy" | wc -l)
etc.