Home > Mobile >  The Linux script does not run on MacOS
The Linux script does not run on MacOS

Time:11-19

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. Any input is much appreciated.

CodePudding user response:

The syntax &>>, which appends both standard output and standard error to the same file, was introduced in bash version 4.0. MacOS ships with bash version 3.2.

You can change it to the more portable syntax:

>> "${TMP_TRANSFER_DIR}/ssl_info_${ssl_host}.txt" 2>&1

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 mapfile built-in, various shell options, etc.

You can install a newer version of bash. The current version is 5.1.

  • Related