I have set | to be the delimiter for a cut command, but space characters seem to still be interpreted as a delimiter too.
Here’s my test script:
people[1]="Mr|Smith"
people[2]="Mrs|Jane Brown"
for person in ${people[@]}
do
title=$(echo $person | cut -f1 -d\|)
name=$(echo $person | cut -f2 -d\|)
echo $title $name
echo
done
Which outputs:
Mr Smith
Mrs Jane
Brown Brown
Can anyone shed some light on why the space character in Jane Brown is causing problems?
Thanks
Simon
Enclose
${people[@]}in double quotes:Otherwise,
Mrs|Jane Brownwill get interpreted as 2 separate tokens:Mrs|JaneandBrown.Think of it as:
versus