dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.
MIT License
36.49k stars 3.28k forks source link

bash string as array #108

Open jeffangelion opened 3 years ago

jeffangelion commented 3 years ago

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