template: dollar variables in sh script (awk, $1, $2)

516 views
Skip to first unread message

Damian Loska

unread,
Dec 27, 2021, 9:07:28 AM12/27/21
to Nextflow
Hey, I have some template script, "test.sh", with a simple line:

zgrep -v "#" $vcfgz  | awk '{print $1}'

However running it from NF

    script:
        template "test.sh"


gives error:

Error executing process > 'test (1)'

Caused by:
  Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/groovy/script/Script58F540A7305FFF8AA14EBC89E87E23F4: 3: token recognition error at: '1' @ line 3, column 28.
   zcat $vcfgz | awk '{print $1}'""");


1 error


So the problems are "dollar" references in the .sh script. Can I somehow omit it? 
Ideally I'd need optional input arguments to the test.sh script:

if it's run standalone, I'd like to run:
bash test.sh firstParamter

and if it's run from NF I'd use only:
template "test.sh" (no need parameters)

Thanks
Damian







Alan Hoyle

unread,
Dec 27, 2021, 10:46:36 AM12/27/21
to next...@googlegroups.com
Try \$1

-- 

From: next...@googlegroups.com <next...@googlegroups.com> on behalf of Damian Loska <damian...@gmail.com>
Sent: Monday, December 27, 2021 9:07:28 AM
To: Nextflow <next...@googlegroups.com>
Subject: template: dollar variables in sh script (awk, $1, $2)
 
--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nextflow/e632abf5-15b6-4675-8c02-4b1b75c2a70fn%40googlegroups.com.

Damian Loska

unread,
Dec 27, 2021, 10:53:27 AM12/27/21
to Nextflow
\$1 doesn't work when I run the script standalone (i,e: bash test.sh firstParam)
I want to easily use the script both from the nextflow, as well as a standalone run

Sam

unread,
Dec 30, 2021, 3:31:54 PM12/30/21
to Nextflow
You can find the related documentation here:

https://www.nextflow.io/docs/latest/process.html?highlight=template

Might need an input val(vcfgz)

Alan Hoyle

unread,
Dec 30, 2021, 4:54:56 PM12/30/21
to next...@googlegroups.com
Maybe Use the shell block documented here:


that makes your nextflow processes use !{varname} and lets you use ${bash_var_name} 

--
  -  Alan Hoyle  -  al...@alanhoyle.com  -  http://www.alanhoyle.com/  -


Damian Loska

unread,
Dec 31, 2021, 4:04:07 AM12/31/21
to Nextflow
Well, your answers are helpful, but partially correct:)

What I needed to do is:

process test {
    echo true
    shell:
        template "my_script.sh"
}

instead of:

process test {
    echo true
    script:
        template "my_script.sh"
}


my_script.sh contains simple:
echo "uuu bbbb" | awk '{print $1}'


THANKS!
DL
Reply all
Reply to author
Forward
0 new messages