Does dash support bash style arrays?

In a shell environment, dash

I want to split a string into arrays. The following code works in bash

, but not in dash

.

IFS=""
var="this is a test|second test|the quick brown fox jumped over the lazy dog"
IFS="|"
test=( $var )
echo ${test[0]}
echo ${test[1]}
echo ${test[2]}

      

My question

Does dash

arrays support this style. Unless there are any suggestions for parsing this expression into another variable type without using a loop?

+3


source to share


1 answer


dash

doesn't support arrays. You can try something like this:



var="this is a test|second test|the quick brown fox jumped over the lazy dog"
oldIFS=$IFS
IFS="|"
set -- $var
echo "$1"
echo "$2"
echo "$3"      # Note: if more than $9 you need curly braces e.g. "${10}"
IFS=$oldIFS

      

+4


source







All Articles