Kunok
Kunok

Reputation: 8759

(${var//=/ }) Doesn't work within Alpine Linux while works fine within zsh. Is there similar alternative?

I am using this snippet to split string into array

line=FOO=BAR
arr=(${line//=/ })

which can be later used such as (to obtain split values):

varname=${arr[0]}

Works great in zsh environment but, it doesn't work within Alpine Linux /bin/sh (perhaps, ash) environment. I am getting:

./env.sh: line 15: syntax error: unexpected "(" (expecting "done")

Is there equivalent string splitting command which works on Alpine Linux?

Upvotes: 0

Views: 784

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295687

Using a heredoc:

line=FOO=BAR
IFS='=' read -r var value <<EOF
$line
EOF

Upvotes: 2

Related Questions