Need Help?

Search our documentation and community forum

Terra is a cloud-native platform for biomedical researchers to access data, run analysis tools, and collaborate.
Terra powers important scientific projects like FireCloud, AnVIL, and BioData Catalyst. Learn more.

'task command' how to work with local variables



  • Avatar
    Sushma Chaluvadi

    I noticed this pattern while working on converting a bash script that I was using locally into a WDL task. I have very much simplified the task but what I noticed is that variables that are defined in the input block of the task are referenced with the `~{myVar}` and then any variables that are created within the task - so, I guess the local variables for the task's VM - have to be referenced as `"$myVar"`. So, in my example below, I defined `~{id_details}` was defined in the input block and then `"$job_id"` was a local variable. Not entirely sure if that helps answer your question but it was what ended up working for me as I transferred by bash code into WDL format.

    task demo_variables {
    input {
    File id_details
    String docker
    command <<<
    awk '{print $1}' OFS="\t" ~{id_details} > id_list.txt

    while IFS="\t" read -r job_id
    bq wait "$job_id"
    echo "$job_id"
    done < job_id_list.txt >> final_details.txt

    runtime {
    docker: docker
    output {
    File final_details = "final_details.txt"
    Comment actions Permalink
  • Avatar
    Andrew Davidson

    Hi Sushma

    thanks for the tip. I think there is a bug in Cromwell. if you comment out a line in your bash task, Cromwell will still try to expand it. this will cause an error if the variable is not defined




    Comment actions Permalink
  • Avatar
    Samantha (she/her)

    Hi Andrew Davidson,

    Sorry for the late response. Can you please paste your full test WDL? I was not able to replicate the error when I tested with each of the following:

    # echo ${myVar} 
    # echo \$myVar
    # how to local variables work?
    # you can not use \$\{var\} you must use dollar var
    count=`ls . | wc -l`
    echo "the number of files in . is $count"




    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk