简体   繁体   English

shell 脚本中的多个 curl 命令

[英]Multiple curl commands in shell script

I have the following code with 3 curl commands in a shell script test.sh.我在 shell 脚本 test.sh 中有以下带有 3 个 curl 命令的代码。

curl -o C:\Users\user1\folder1\folder2\folder3\folder4\25Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=25Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
curl -o C:\Users\user1\folder1\folder2\folder3\folder4\24Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=24Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
curl -o C:\Users\user1\folder1\folder2\folder3\folder4\23Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=23Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"

I am using a Windows 10 machine and when I try to execute the shell script at command prompt using sh test.sh , the files don't download as expected.我使用的是 Windows 10 机器,当我尝试使用sh test.sh在命令提示符下执行 shell 脚本时,文件没有按预期下载。 If I take the individual curl commands and execute them at command prompt, they work perfectly fine.如果我使用单独的 curl 命令并在命令提示符下执行它们,它们就可以正常工作。 I tried tweaking the shell script and removing "\\r" and running this.我尝试调整 shell 脚本并删除 "\\r" 并运行它。 Are there any additional things that I can try to make this work?我可以尝试做任何其他事情吗?

I edited the Shell script to run just one of the curl commands as well and here are the results.我编辑了 Shell 脚本以仅运行其中一个 curl 命令,结果如下。

This is the output with running the shell script as sh test.sh这是将 shell 脚本作为sh test.sh运行的输出

>sh test1.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    29    0    29    0     0     29      0 --:--:-- --:--:-- --:--:--    56

This is the output of one of the individual curl commands:这是单个 curl 命令之一的输出:

curl -o C:\Users\user1\folder1\folder2\folder4\folder4\25Oct2021.gz "https://abc.xyz.aaa.com/v3/test-logs/download?userID=AA4d3DFF&fileName=25Oct2021.gz" --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 4035k    0 4035k    0     0   672k      0 --:--:--  0:00:06 --:--:--  838k

\\ is an escape character in (ba)sh, but not in the Windows command prompt, which explains the difference in execution. \\是 (ba)sh 中的转义字符,但不是 Windows 命令提示符中的转义字符,这解释了执行中的差异。

You need to either double the backslashes ( \\\\ ), enclose each string containing backslashes inside single quotes ( ' ), or replace all backslashes by forward slashes ( / ).您需要将反斜杠 ( \\\\ ) 加倍,将每个包含反斜杠的字符串括在单引号 ( ' ) 内,或者用正斜杠 ( / ) 替换所有反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM