• We implementing as below code using for loop but wrong output coming after running the script.
[pastacode lang=”bash” manual=”for%20i%20in%20%60awk%20-F%22%7C%22%20’%7Bprint%20%241%7D’%20%24INPUTFILE%60%2C%20j%20in%20%60awk%20-F%22%7C%22%20’%7Bprint%20%242%7D’%20%24INPUTFILE%60%0Ado%0Aecho%20%24i%3A%24j%0Adone%20%20%0A” message=”bash code” highlight=”” provider=”manual”/]

[pastacode lang=”bash” manual=”while%20IFS%3D’%7C’%20read%20-r%20i%20j%20rest%20%3C%263%3B%20do%0A%20%20%7B%0A%20%20%20%20printf%20’%25s%5Cn’%20%22something%20with%20%24i%20and%20%24j%22%0A%20%20%7D%203%3C%26-%0Adone%203%3C%20%22%24INPUTFILE%22%0A” message=”bash code” highlight=”” provider=”manual”/] [ad type=”banner”]
  • But using a shell loop to process text is often the wrong way to go.
[pastacode lang=”bash” manual=”awk%20-F%20’%7C’%20’%7Bprint%20%241%20%22%3A%22%20%242%7D’%20%3C%20%22%24INPUTFILE%22%0A” message=”bash code” highlight=”” provider=”manual”/]

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”/]

Categorized in: