macos 终端命令:带有回声的循环
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7165774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Terminal Commands: For loop with echo
提问by Chris
I've never used commands in terminal like this before but I know its possible. How would I for instance write:
我以前从未在终端中使用过这样的命令,但我知道这是可能的。例如,我将如何写:
for (int i = 0; i <=1000; i++) {
echo "http://example.com/%i.jpg",i
}
回答by Simon
The default shell on OS X is bash. You could write this:
OS X 上的默认 shell 是 bash。你可以这样写:
for i in {1..100}; do echo http://www.example.com/${i}.jpg; done
Here is a link to the reference manual of bash concerning loop constructs.
这是有关循环结构的 bash 参考手册的链接。
回答by Gordon Davisson
for ((i=0; i<=1000; i++)); do
echo "http://example.com/$i.jpg"
done
回答by Cygnusx1
Is you are in bash shell:
您是否在 bash shell 中:
for i in {1..1000}
do
echo "Welcome $i times"
done
回答by thomas
jotwould work too (in bash shell)
jot也可以(在 bash shell 中)
for i in `jot 1000 1`; do echo "http://example.com/$i.jpg"; done
回答by Grimmace
By using jot:
通过使用jot:
jot -w "http://example.com/%d.jpg" 1000 1
回答by vishal
you can also use for loop to append or write data to a file. example:
您还可以使用 for 循环将数据追加或写入文件。例子:
for i in {1..10}; do echo "Hello Linux Terminal"; >> file.txt done
">>" is used to append.
“>>”用于追加。
">" is used to write.
">" 用于书写。