This error originally occurred during an apt upgrade but I managed to reproduce it with update grub
sudo update-grub
[sudo] password for me:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-72-generic
Found initrd image: /boot/initrd.img-4.15.0-72-generic
Found linux image: /boot/vmlinuz-4.15.0-60-generic
Found initrd image: /boot/initrd.img-4.15.0-60-generic
Found linux image: /boot/vmlinuz-4.15.0-20-generic
Found initrd image: /boot/initrd.img-4.15.0-20-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
error: syntax error.
error: Incorrect command.
error: syntax error.
Syntax error at line 145
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
I perused /etc/default/grub
and /etc/grub.d/* files and didn't find any obvious errors.
During my search for information I found https://unix.stackexchange.com/questions/209152/syntax-error-in-grub-cfg-on-update-grub-grub-2-memtest86 but the excellent troubleshooting steps there didn't result in a solution for me. Sadly I failed to backup /boot/grub/grub.cfg.new prior to resolving the problem so I cannot provide a copy, all I recall is that the error was reported on line 145 and there were not any issues that I could see with the if - fi code block in the area of that line.