Shell - 回显一些命令(curl)vs在终端中输入命令

时间:2017-12-20 19:45:08

标签: shell curl echo

为什么我这样做的结果不一样:
1.转到我的终端并输入

curl -I www.httpbin.org

结果:

HTTP/1.1 200 OK
Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 20 Dec 2017 19:20:56 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 13011
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.00580310821533
Via: 1.1 vegur

2。创建文件APIConnection.sh
包含:

#! /bin/bash

api_url_1="www.httpbin.org"

echo `curl -I $api_url_1`

然后转到我的终端并执行文件:./APIConnection.sh 结果:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
  0 13011    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  Via: 1.1 vegurme: 0.0147929191589 true

2 个答案:

答案 0 :(得分:2)

Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = Me.Range("D8").Address Then 'i moved input cell to D8 Application.ScreenUpdating = False Range("F14:Z14").EntireColumn.Hidden = False 'this range is the total for the number of years you have Dim hideYears As Range Set hideYears = Me.Range("F14").Offset(0, Target.Value) Set hideYears = Range(hideYears, hideYears.End(xlToRight)) hideYears.EntireColumn.Hidden = True End If End Sub 中解释了在反叛之间运行curl时仅显示进度条的原因:

  

进度表

man curl

如果您想明确关闭进度表,可以使用 curl normally displays a progress meter during operations, indicating the amount of transferred data, transfer speeds and estimated time left, etc. The progress meter displays number of bytes and the speeds are in bytes per second. The suffixes (k, M, G, T, P) are 1024 based. For example 1k is 1024 bytes. 1M is 1048576 bytes. curl displays this data to the terminal by default, so if you invoke curl to do an operation and it is about to write data to the terminal, it disables the progress meter as otherwise it would mess up the output mixing progress meter and response data. 完成此操作。

--silent是bash和其他符合POSIX标准的shell中command substitution的遗留语法。这意味着输出由shell捕获,而不是直接写入终端。由于``无法检测到curl稍后将其写入终端,因此它不会如上所述禁用进度表。

如果你真的想在这里使用命令替换(而不是让你的脚本运行echo而没有任何命令替换 echo),请在命令替换周围加上引号以避免字符串拆分和全局扩展。

建议使用现代命令替换语法curl -I "$api_url_1",因此每个替换都有自己的引用上下文:

$()

答案 1 :(得分:0)

执行curl -I www.httpbin.org会在执行echo `curl -I $api_url_1`时为您提供标准输出的结果,从而为您提供标准错误的结果。 要查看差异,请执行以下命令,然后查看已创建的se.txtso.txt文件的内容:

 curl -I www.httpbin.org 1>so.txt 2>se.txt

查看about stdin, stdout and stderr了解详情。

相关问题