Bash : Native way to get rid of quotation around each array member

arraybashshell-scriptstring

I read an array from another script. This array needs to put " " around all array members since some members are empty.

in_file=./data
vector=($(./readdata.sh 0 $in_file))
for index in ${!vector[@]}
do
    echo ${vector[index]}
done

The problem is that I have quotations around each output line and I want to get rid of them.

"red"
"blue"
"green"
""
"white"
"black"

must change to:

red
blue
green

white
black

I look for a method which does not use awk, tr, sed or any other pipeline based way. I just want to solve with using native ways such as using parenthesis, different punctuations, ….

Best Answer

This might work:

in_file=./data
vector=($(./readdata.sh 0 $in_file))
for index in ${!vector[@]}
do
    echo ${vector[index]//\"/}
done

Ref: http://www.tldp.org/LDP/abs/html/refcards.html#AEN22828

Related Question