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

Iterate over characters in a string #17

Open
spiralofhope opened this issue Jul 25, 2020 · 0 comments
Open

Iterate over characters in a string #17

spiralofhope opened this issue Jul 25, 2020 · 0 comments

Comments

@spiralofhope
Copy link

Drawn from https://stackoverflow.com/a/51052644/1190568

string='example'
__="$string"
while [ -n "$__" ]; do
  # All but the first character of the string
  rest="${__#?}"
  #  Remove $rest, and you're left with the first character
  first_character="${__%"$rest"}"
  echo "$first_character"
  __="$rest"
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