如何在bash脚本的循环中使用参数运行curl命令?

时间:2015-09-25 22:41:01

标签: linux bash curl scripting

我有一个curl命令,我想在for循环中执行。 例如,我想循环1-100次,当curl命令运行时,它在curl命令本身中使用iterator变量值。

之类的东西
#!/bin/bash
  for i in {1..10}
 do
    curl -s -k 'GET' -H 'header info' -b 'stuff' 'http://example.com/id=$i'        
 done
 --notice here I want var i to be changing with every curl.

一切都有帮助 谢谢。

1 个答案:

答案 0 :(得分:13)

试试这个:

set -B                  # enable brace expansion
for i in {1..10}; do
  curl -s -k 'GET' -H 'header info' -b 'stuff' 'http://example.com/id='$i
done

请参阅:Difference between single and double quotes in Bash