Dears,
Simple question, I have a shell variable with the following values,
myarr=["Life","is","good","when","you","learning"]
It is an array of strings ! Here is how I want to print it. Also, I need to do with a loop because each of these element would be passed to a function to process the string
Expected Output
Life \
is \
good \
when \
you \
learning
>Solution :
You can make a for loop to print all the elements of your array.
# declare your array variable
declare -a myarr=("Life","is","good","when","you","learning")
# get length of an array
length=${#myarr[@]}
for (( j=0; j<${length}; j++ ));
do
printf "${myarr[$j]}\n"
done