我想写一个简单的脚本,它将检查在数组中声明的URL并以下面的格式显示结果:
http://google.de : 301 Moved Permanently (http://www.google.de/)
http://google.fr : 301 Moved Permanently (http://www.google.fr/)
https://stackoverflow.com : 200 OK
这是我的剧本:
#!/usr/bin/env bash
sites=(
http://google.de
http://google.fr
https://stackoverflow.com
)
for site in ${sites[*]}; do
headers=$(curl -Is ${site})
status=$(echo "$headers" | head -n 1 | cut -c10-)
location=$(echo "$headers" | grep 'Location' | cut -c10-)
echo -n "$site : "
echo -n "$status"
if [[ ! -z "$location" ]]; then
echo -n " ($location)"
fi
echo -e "\n"
done;
无论如何它返回输出:
)( http://www.google.de/Moved Permanently
)( http://www.google.fr/oved Permanently
https://stackoverflow.com : 200 OK
我不明白为什么这些字符串会以如此奇怪的方式被覆盖。
修改
我上传了bash -x myfile
- https://pastebin.com/guMJC24h