终端命令:用于带回声的循环

时间:2011-08-23 18:25:26

标签: macos terminal command

我之前从未在终端中使用过命令,但我知道它可能。我将如何写:

for (int i = 0; i <=1000; i++) {
    echo "http://example.com/%i.jpg",i
}

6 个答案:

答案 0 :(得分:96)

OS X上的默认shell是bash。你可以这样写:

for i in {1..100}; do echo http://www.example.com/${i}.jpg; done

以下是reference manual of bash concerning loop constructs的链接。

答案 1 :(得分:19)

for ((i=0; i<=1000; i++)); do
    echo "http://example.com/$i.jpg"
done

答案 2 :(得分:3)

你是否在bash shell中:

for i in {1..1000}
do
   echo "Welcome $i times"
done

答案 3 :(得分:2)

jot 也会起作用(在bash shell中)

for i in `jot 1000 1`; do echo "http://example.com/$i.jpg"; done

答案 4 :(得分:1)

使用 jot

jot -w "http://example.com/%d.jpg" 1000 1

答案 5 :(得分:0)

您还可以使用for循环将数据附加或写入文件。例如:

for i in {1..10}; do echo "Hello Linux Terminal"; >> file.txt done

“&GT;&gt;” 中用于追加。

“&gt;” 中用来写。