Bash: "syntax error near unexpected token" that's a valid token

562 views Asked by At

I have the following bash code in a script file:

if [ 'false' == 'true' ]
then
        write_map() >> 'groups.txt'
        Groups='groups.txt'
fi

When I try to run the script, I get this message from bash, and nothing is run:

syntax error near unexpected token `>>'
  1. Why is >> an "unexpected token?
  2. Why is bash failing on code that is inside an "if" that won't be run?
  3. This bash code was created by Cromwell wdl. write_map is a wdl function, not a bash function. Could that be what's breaking bash?
1

There are 1 answers

0
Greg Dougherty On

So, there were two issues

  1. write_map was being called wrong in the wdl code that was the source for this bash code
  2. When called correctly, write_map is turned into a file, and you can't >> a file (you have to cat it then >>)