[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: split(): syntax error near unexpected token `(' ... [OT]



Bash does not have a split function. To split in bash, one has to do it the 
old-fashioned way:

declare -i i
declare -a myArray

OIFS=$IFS
IFS=":"
set `egrep root /etc/passwd`
IFS=$OIFS

# Store the new positional parameters in indexed array myArray.
i=0
while [ ! -z $1 ]; do
  myArray[$i]=$1
  shift
  i=i+1
done

# Display the elements of myArray
i=0
while [ $i -lt ${#myArray[@]} ]; do
  echo ${myArray[$i]}
  i=i+1
done


Reply to: