How can I add a new line to following bash array? The get_group is a function, it assigns a list of members in a group to the GROUP, but the statement GroupList+=${GROUP} stacks the end of the first group and the start of the second group in one line, I tried to add new line to the array, that does not work at all
declare -a GroupList=()
for i in $(seq 1 3); do
GROUP=$(get_group ${i})
GroupList+=${GROUP}
GroupList+="\n" # does not work
done
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
How to add a new line to a bash array?
- Head_on_a_Stick
- Posts: 14114
- Joined: 2014-06-01 17:46
- Location: London, England
- Has thanked: 81 times
- Been thanked: 133 times
Re: How to add a new line to a bash array?
afaiu, you don't really need the actual newline, but need to make sure that each
adds one more member to the array, yes?
i have never tried the '+=' syntax on arrays;
you can see if it worked like this:
Code: Select all
GroupList+=${GROUP}
i have never tried the '+=' syntax on arrays;
you can see if it worked like this:
Code: Select all
for (( i=0;i<${#GroupList[@]};i++ )); do
echo "GroupList[$i]: ${GroupList[i]}"
done