Well in my script I use a simple line to tokenize:
IFS=';' read -ra ALL_ADDR <<< "${SERVER}"
However the moment I run this script in a busybox (alpine) linux docker container, it stumbles around above line. line 43: syntax error: unexpected redirection
I understand this is because the script is not run by Bash
but rather Ash
, which does not have the <<<
redirect parameter. How can I transform the above line into code that works similar around all popular shell scripts. (Mainly Bash, Ash and Dash)?
for completeness the variable is like:
SERVER="/api/v1:127.0.0.1:1337;/api/v2:127.0.0.1:1338"
IFS=';' read -ra ALL_ADDR <<< "${SERVER}"
for i in "${ALL_ADDR[@]}"; do
IFS=':' read -ra ADDR <<< "${i}"
PROXY=${ADDR[0]}
IPADDR=${ADDR[1]}
PORT=${ADDR[2]}
LOC_STRING="${LOC_STRING}\tlocation ${PROXY} {\n\t\tproxy_pass http://${IPADDR}:${PORT}\n\t}\n"
done
LOC_STRING=${LOC_STRING//\//\\\/}
#"insert" above generated lines into a site config for nginx
sed -e "0,/^\s*location/{s/^\s*location/${LOC_STRING}\n&/}" 'portal' > "../sites-enabled/portal"