![bash 中的嵌套 for 循环](https://linux22.com/image/89272/bash%20%E4%B8%AD%E7%9A%84%E5%B5%8C%E5%A5%97%20for%20%E5%BE%AA%E7%8E%AF.png)
你好我想问你,我怎样才能在bash中编写相同的循环
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
System.out.println(i + " " + j);
}
}
答案1
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
请参阅此处了解更多信息:http://www.tldp.org/LDP/abs/html/loops1.html