I`m trying to expand a variable inside parallel for a program argument
For example TAG=IMPACT
ls *vcf | parallel -k -v 'bcftools query -f "%$TAG/n"'
Where it should be expanded to
ls *vcf | parallel -k -v 'bcftools query -f "%IMPACT/n"'
I tried many variantions of "" and '' as I could think of, but I always get
bcftools query -f %IMPACT/n
bcftools query -f '"%$TAG/n"'
Or anything else like
bcftools query -f '"%"$TAG"\n"'
Tried some variantions of parallel like --shellquote but no combination worked out and expanded correctly (if it is possible at all)
I tried by delimiting everything inside $TAG like:
TAG="%IMPACT/n"
then
ls *vcf | parallel -k -v 'bcftools query -f '"%$TAG/n"''
Which could work, but is there a way to expand it inside the code and not outside of it?
Just as a test that I was doing, Using
ls *vcf | parallel -k -v 'bcftools +split-vep -f '"$TAG"' {} | tr '"$COMMA"' '"$SPACE"''
When defining
TAG='"%IMPACT/n"'
SPACE='"/n"'
COMMA='","'
Expands to:
bcftools +split-vep -f "%IMPACT/n" input.vcf | tr "," "/n"
Since
parallelis being started in a subprocess make sure toexport TAGbeforehand to insureparallelcan properly expand$TAGat run time:Alternatively, allow
$TAGto be expanded by the OS by wrapping theparallelscript in double quotes:If you need to maintain the inner double quotes then escape them: