dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bash string as array

jeffangelion opened this issue · comments

The trick is using ranges
Example:

#!/usr/bin/env bash

string="123456789"
string_length=${#string}
for ((index = 0 ; index < $string_length ; index++)); do
    echo $((${string:$index:1} * 10)) # we can use string as pseudo-array by setting range length to 1
done