I'm running a script in Bash on a Mac and I am trying to split a string with the delimiter being a space into an array. The command I'm running is:
array = ($(echo "$string" | tr ' ' "\n"))
that returns the "unexpected '('" error. I've tried multiple solutions including
- escaping the parentheses
- putting quotes around the command
- making sure the space wasn't causing the error
- making sure my header is
#!/bin/bash
shellcheck
to help you debug scripts:sudo apt-get install shellcheck
– George Udosen Jun 22 '18 at 20:42var_name=word
, that is no-space between name,=
, andword
is POSIX-specified, so . . . version is actually irrelevant here and non-Mac specific. – Sergiy Kolodyazhnyy Jun 23 '18 at 20:31