Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

bash string as array #108

Open
jeffangelion opened this issue Nov 16, 2020 · 0 comments
Open

bash string as array #108

jeffangelion opened this issue Nov 16, 2020 · 0 comments

Comments

@jeffangelion
Copy link

jeffangelion commented Nov 16, 2020

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant