- We implementing as below code using for loop but wrong output coming after running the script.
- But using a shell loop to process text is often the wrong way to go.
Now as an answer to the question in the title, for a shell with for loops taking more than one variables, you’ve got zsh (you seem to already be using zsh syntax by not quoting your variables or not disabling globbing when splitting command substitution):
[pastacode lang=”bash” manual=”%24%20for%20i%20j%20in%20%7B1..6%7D%3B%20do%20echo%20%24i%3A%24j%3B%20done%0A1%3A2%0A3%3A4%0A5%3A6%0A” message=”bash code” highlight=”” provider=”manual”/] [ad type=”banner”]Or the shorter form:
[pastacode lang=”bash” manual=”for%20i%20j%20(%7B1..6%7D%20echo%20%24i%3A%24j%0A” message=”bash code” highlight=”” provider=”manual”/]The equivalent with POSIX shells:
[pastacode lang=”bash” manual=”set%20–%201%202%203%204%205%206%0A%23%23%20or%3A%0A%23%20IFS%3D’%0A%23%20’%20%23%20split%20on%20newline%0A%23%20set%20-f%20%23%20disable%20globbing%0A%23%20set%20–%20%24(awk%20…)%20%23%20split%20the%20output%20of%20awk%20or%20other%20command%0Awhile%20%5B%20%22%24%23%22%20-gt%200%20%5D%3B%20do%0A%20%20echo%20%22%241%3A%242%22%0A%20%20shift%202%0Adone%0A” message=”bash code” highlight=”” provider=”manual”/]
superb