0

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?
Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58
  • 2
    `write_map()` is the problem; that's not a valid shell command (it looks like the beginning of a function definition, which can't be followed by `>>`). The code is failing because bash can't parse the file. If `write_map()` is not a bash function, what is it doing in a bash script? – larsks Feb 17 '22 at 16:16
  • 2
    `write_map()` is the beginning of a `bash` function definition and is expected to be followed by the token `{`, but since the token `>>` is not the same as the token `{` you receive the message `unexpected token '>>'`; I'm not familiar with `Cromwell wdl` so have no idea how/why it would create this invalid (`bash)` syntax – markp-fuso Feb 17 '22 at 16:20

1 Answers1

0

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 >>)
Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58