This question already has answers here:
Difference between single and double quotes in Bash

(6个答案)


5年前关闭。




我有一个curl命令,我想在for循环中执行。
例如,我想循环1-100次,而curl命令运行时,它将在curl命令本身中使用迭代器变量值。
就像是
#!/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.

有什么帮助
谢谢。

最佳答案

试试这个:

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

关于linux - 如何从bash脚本循环运行带有参数的curl命令?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32791663/

10-13 09:23