How to avoid separators to be printed on screen when printing a whole array in bash script -
i have strange issue script , know if exists solution rid of it.
i have put in script test out :
#!/bin/bash # clear screen clear # define array array=("\e[2;3hline one" "\e[3;3hline two" "\e[4;3hline three") # change background color "teal" , foreground color "black" echo -e "\e[0;30m\e[46m" # print each line 1 one on screen # works expected, nothing echo -e "${array[0]}" echo -e "${array[1]}" echo -e "${array[2]}" # exact same text, moved text below previous 1 make easier compare array=("\e[6;3hline one" "\e[7;3hline two" "\e[8;3hline three") # print entire array in 1 shot, gain speed # not work expected there "space" @ end of 2 first lines echo -e "${array[@]}" # reset colors normal echo -e "\e[0m"
when launching it, can see in 2nd printing there "space" @ end of 1st , 2nd line.
the question : how rid of these spaces ?!
note : need formating , need print whole array @ once... , way, played ifs , character substitution nothing worked expected far...
edit : solution proposed cyrus below using "printf" instead of "echo" seems work expected (i'm not sure of pros , cons of using instead of "echo" builtin job).
solution :
printf "%b\n" "${array[@]}"
instead of :
echo -e "${array[@]}"
thanks again cyrus help.
replace
echo -e "${array[@]}"
by
printf "%b\n" "${array[@]}"
Comments
Post a Comment