在 bash 中嵌套 for 循环

Jav*_*eak -1 bash

你好,我想问你,我怎样才能在 bash 中写出完全相同的循环

for (int i = 0; i < a; i++) {
    for (int j = i; j < a; j++) {
        System.out.println(i + " " + j);
    }
}
Run Code Online (Sandbox Code Playgroud)

lee*_*sky 5

bash 支持 C 风格的 for 循环如下:

a=5 # example

for ((i = 0; i < a; i++)); do
  for ((j = i; j < a; j++)); do
    echo "$i $j"
  done
done
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参见此处:http : //www.tldp.org/LDP/abs/html/loops1.html