How to iterate over the characters of a string in a POSIX shell script?
问题 A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings: for x in $(seq 1 5); do echo $x done But, how do I iterate over each character of a word? 回答1: It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in dash , but I don't have busybox handy to test with. var='ab * cd' tmp="$var" # The loop will consume the variable, so make a temp copy first while [ -n "$tmp" ]; do rest="${tmp#?}" # All but the first