-1

Hello I would like to ask you, how can I write the same exact loop in bash

for (int i = 0; i < a; i++) {
    for (int j = i; j < a; j++) {
        System.out.println(i + " " + j);
    }
}
4
  • What did you try?
    – Mikel
    Jun 23, 2016 at 23:19
  • actually i tried for a in b yet.. i was not successful and i am a big beginner in bash
    – JavaFreak
    Jun 23, 2016 at 23:20
  • 1
    is this related to unix.stackexchange.com/questions/291624/… ?
    – Archemar
    Jun 24, 2016 at 6:31
  • No sir, it is not related, i was actually trying to come up with two different versions
    – JavaFreak
    Jun 24, 2016 at 19:09

1 Answer 1

5

bash supports C-style for loops as follows:

a=5 # example

for ((i = 0; i < a; i++)); do
  for ((j = i; j < a; j++)); do
    echo "$i $j"
  done
done

See here for more: http://www.tldp.org/LDP/abs/html/loops1.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.