I would like to write simple script which will check URLs declared in array and display the result in the format below:
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
Here is my script:
#!/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;
Anyway it returns the output:
)( http://www.google.de/Moved Permanently
)( http://www.google.fr/oved Permanently
https://stackoverflow.com : 200 OK
I do not understand why those strings are overwritten in such weird way.
EDIT:
I have uploaded the result of bash -x myfile
– https://pastebin.com/guMJC24h