I have a script for work which runs fine on Ubuntu Virtual machine. I have recently switched to MacOS and while trying to run the same script I get the following error:
danyateran@MacBook-Air-Danya:~/restorator$ ./restorator.sh -V
/Users/danyateran/restorator/bin/functions.sh: line 1568: syntax error near unexpected token `>'
/Users/danyateran/restorator/bin/functions.sh: line 1568: ` ssh_conn "${SOURCE_SERVERNAME}" 'exec 2>&1; whmapi1 fetch_ssl_certificates_for_fqdns domains='${ssl_host}'; exit' &>> "${TMP_TRANSFER_DIR}/ssl_info_${ssl_host}.txt"'
While the syntax seems fine and as far as I know the MacOS has the same line endings as Linux, I have no idea what could be wrong. What is the cause of this MacOS-related problem and how can it be resolved?
The syntax
&>>, which appends both standard output and standard error to the same file, was introduced in bash version4.0. MacOS ships with bash version3.2.You can change it to the more portable syntax:
That's same thing, but will be understood by bash v3.2 (and newer, and
sh).However, there might be other things in the script which are not compatible, such as associative arrays, the
mapfilebuilt-in, various shell options, etc.You can install a newer version of bash. The current version is
5.1.