[Solved] print chars of a string

how can i print all the chars of a string one by line?
i have thought that use a for cicle and use this command inside:

${VARIABLE:0:last}

but how can i make last? because string is random
P.S. VARIABLE is the string
or can i make a variable for every chars of this string?

this was my idea but doesn't work

i=0;
for CAR in ${VARIABLE:0:i} ; do {
    echo $CAR;
    i=$((i+1));
    }
done
last=${#VARIABLE}

try (bash shell only):

var="thingtoprint"
for i in ` seq ${#var}` 
do
  echo ${var:$i:1}
done

doesn't work.
with this, it prints blank lines as many as number of chars of string

Show exactly what you tried.

What's your shell?

my shell is bash
i want to extract all chars from a string and put every on a different variable

---------- Post updated at 09:51 AM ---------- Previous update was at 09:37 AM ----------

thanks i resolved :smiley:

What did you resolve, for the benefit of future struggling googlers?

last=${#VARIABLE}
for ((i=0;i<$last;i++)) ; do 
        CAR=${VARIABLE:i:1};
        echo $CAR;
done

You can simplify that.

for ((i=0;i<${#VARIABLE};i++)) ; do 
        echo ${VARIABLE:i:1};
done

thanks :smiley:

---------- Post updated at 01:34 PM ---------- Previous update was at 10:11 AM ----------

instead if i want to put every chars on a different variables for each chars?

Since you have BASH, you ought to have arrays:

VARIABLE="slartibartfast"
for ((i=0;i<${#VARIABLE};i++))
do 
        ARR="${VARIABLE:i:1}"
        echo "ARR = ${ARR}"
done
$ ./myscript

ARR[0] = s
ARR[1] = l
ARR[2] = a
ARR[3] = r
ARR[4] = t
ARR[5] = i
ARR[6] = b
ARR[7] = a
ARR[8] = r
ARR[9] = t
ARR[10] = f
ARR[11] = a
ARR[12] = s
ARR[13] = t

$

thanks a lot :smiley: