Separate characters in a string
Posted: 2021-Jul-25, 12:15 pm
03 May 2009 06:51
Leo_Gutierrez
Hi.
How can I separate this string:
like this:
I want to put each character in to a subscript of a array.
like this
Thanks a lot.
----------------------------
#2 03 May 2009 07:26
Leo_Gutierrez
I found the solution:
Output:
Thanks.
Leo_Gutierrez
Hi.
How can I separate this string:
Code: Select all
"Leonardo"
Code: Select all
L
e
o
n
a
r
d
o
like this
Code: Select all
array[0]=L
array[1]=e
array[2]=o
...
----------------------------
#2 03 May 2009 07:26
Leo_Gutierrez
I found the solution:
Code: Select all
#!/usr/bin/bash
name="Leonardo"
longitud=`expr length "$name"`
for i in $(seq 0 $longitud);
do
echo ${name:$i:1}
done
Code: Select all
leo@lein:~/Escritorio/bash$ bash shell.sh
L
e
o
n
a
r
d
o
leo@lein:~/Escritorio/bash$