Say I have ./param HEY
What would I do if I wanted to store each character into an array?
Example.
ARRAY1[0]="H"
ARRAY1[1]="E"
ARRAY1[2]="Y"
thank you!
Say I have ./param HEY
What would I do if I wanted to store each character into an array?
Example.
ARRAY1[0]="H"
ARRAY1[1]="E"
ARRAY1[2]="Y"
thank you!
S="HELLOWORLD"
for ((i=0; i<${#S}; i++))
do A[$i]=${S:$i:1}
done
Neat /bin/bash solution frans, here is one with /bin/sh
#!/bin/sh
i=1
LEN=$( echo $1 | wc -c )
while [ $i -lt $LEN ]
do
ARRAY[$i]="$( echo $1 | cut -c$i )"
let i=i+1
done
echo Element #3 is ${ARRAY[3]}
I like this answer!
I don't look like your sh is symlinked to bash
Did you know that
Should be
LEN=${#$1}
why is that?