在bash中读取文件时在循环中运行curl commads

在bash中读取文件时在循环中运行curl commads,bash,for-loop,curl,Bash,For Loop,Curl,我尝试逐行解析一个文件,然后尝试运行其中的所有curl命令,然后记录成功的v/unsuccessful调用 cat file /usr/bin/curl -X POST http://localhost/services/migration -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d ' [{"resources": [{"name": "Provi

我尝试逐行解析一个文件,然后尝试运行其中的所有curl命令,然后记录成功的v/unsuccessful调用

cat file 

/usr/bin/curl  -X POST http://localhost/services/migration -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d ' [{"resources": [{"name": "Provisioned Throughput (at peek load)","value": "514"}],"entityTypes": [{"app": "thanos"}],"subEntityTypes": [{"vapps": "loki-odinson"}],"user": "foobar@tt.com"}]';
/usr/bin/curl  -X POST http://localhost/services/migration -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d ' [{"resources": [{"name": "Provisioned Throughput (at peek load)","value": "5124"}],"entityTypes": [{"app": "stark"}],"subEntityTypes": [{"vapps": "tony-s"}],"user": "foobar@tt.com"}]';
我正在逐行解析文件。echo语句工作得很好,并给了我curl命令,但当我试图简单地运行它时,它给了我-bash:没有这样的文件或目录错误

我可以获取整个文件的源代码,但如果要记录有多少失败的vs成功,那将是一件痛苦的事情

下面是我试图运行的命令

IFS=$'\n'
for var in `cat ten`; do $var ; sleep 1 ; done

要运行名为commands.txt的文件中列出的每个命令,只需将其视为脚本:
bash commands.txt

也就是说,循环有几个问题:

  • 全局覆盖
    IFS
    将导致一些奇怪的行为。基本上,您只需要为单个命令覆盖它,如
    IFS=$'\n'命令中的
  • 您需要处理非平凡的参数(例如包含空格的参数)
  • 试着设一个陷阱

    $:  cat x
    trap 'echo "$BASH_COMMAND">>errs' ERR
    echo 1 2 3 4
    bogus 5 6 7 8
    true this one
    false this one
    $: ./x
    1 2 3 4
    bash: bogus: command not found
    $: cat errs
    bogus 5 6 7 8
    false this one
    ./x
    
    errs
    现在是失败的错误列表
    grep-vf errs x
    以获取成功的错误。(将包括存水弯。)

    检查存水弯。