[shell]curl结果获取http header的问题
来源:互联网 发布:淘宝墙贴 编辑:程序博客网 时间:2024/06/06 01:16
在通过curl请求http获取response header时, 发现字符串拼接一个问题。
比如以下程序:
hadoop@1:~$ ct=$(curl -s -I http://www.baidu.com | grep Content-Type | awk '{print $2}')hadoop@1:~$ echo $cttext/htmlhadoop@1:~$ echo $ct"_postfix"_postfixl
最后一行输出竟然是: _postfixl
, 而不是期待的text/html_postfix
细看结果应该是_postfix
直接覆盖了text/html
前面的内容。
http header是以\r\n
作为行分割符,与echo机制有什么冲突?
原因未解, 不过找到这样一种替代方法(如test.sh):
shopt -s extglob # 识别正则, 用于后面去掉空格function grepCT(){ while IFS=':' read key value; do # 去掉"value"内的空格 value=${value##+([[:space:]])}; value=${value%%+([[:space:]])} case "$key" in Server) SERVER="$value" ;; Content-Type) CT="$value" ;; HTTP*) read PROTO STATUS MSG <<< "$key{$value:+:$value}" ;; esac done < <(curl -sI $1) echo $CT}ct=$(grepCT http://www.baidu.com)echo $ct"_postfix"
执行shell文件:
hadoop@1:~$ bash test.shtext/html_postfix
阅读全文
1 0
- [shell]curl结果获取http header的问题
- shell curl http状态码获取
- 通过cURL获取web页面及http header信息
- curl_slist_append增加http header -- curl
- Linux下curl模拟带header的Http请求
- curl 获取数据的问题
- curl获取服务器响应的http头
- 获取cURL请求的HTTP状态
- curl——HTTP协议.header
- curl 获取google搜索结果
- HTTP/1.1协议的curl 返回 HTTP/1.1 100 Continue 加上header 加上body
- HTTP/1.1协议的curl 返回 HTTP/1.1 100 Continue 加上header 加上body
- libcurl库cURL成功链接,但无法获取到参数 HTTP请求的参数问题
- 获取python执行shell命令的结果
- Perl 获取shell命令的执行结果
- shell获取命令的输出结果
- linux shell命令的结果获取
- makefile 获取shell命令的结果
- ResourceBundle missingresourceexception
- fastjson序列化hibernate查询的数据报错:failed to lazily initialize a collection of role
- 10 个快速提升技术水平的方法
- Eclipse配置多域名启动项目详细步骤
- C读书笔记
- [shell]curl结果获取http header的问题
- 171024-对do-while,while,for语句的复习
- RDD日常操作函数详解
- insmod 的一些权限
- 欢迎使用CSDN-markdown编辑器
- 观看杜洋工作室焊接入门个人总结
- spring eurake中使用IP注册
- springboot填坑之 -- spring cloud基于ip的discovery服务注册中心配置
- Gym 101343.J