Sit*_*hsu 28
执行以下操作script.sh http://www.google.com/.
-D- 将头转储到文件
-o- 写入对文件的响应
-s- 保持沉默
-w- 显示指定变量的值
#!/bin/bash
RESPONSE=response.txt
HEADERS=headers.txt
status=$(curl -s -w %{http_code} $1 -o $RESPONSE)
# or
#curl -s -D $HEADERS $1 -o $RESPONSE
#status=$(cat $HEADERS | head -n 1 | awk '{print $2}')
echo $status
Run Code Online (Sandbox Code Playgroud)
使用$status和$RESPONSE进一步处理.