Script to get the HTTP status code of a list of urls?

Curl has a specific option, –write-out, for this: $ curl -o /dev/null –silent –head –write-out ‘%{http_code}\n’ <url> 200 -o /dev/null throws away the usual output –silent throws away the progress meter –head makes a HEAD HTTP request, instead of GET –write-out ‘%{http_code}\n’ prints the required status code To wrap this up in a complete Bash … Read more

Read a variable in bash with a default value

You can use parameter expansion, e.g. read -p “Enter your name [Richard]: ” name name=${name:-Richard} echo $name Including the default value in the prompt between brackets is a fairly common convention What does the :-Richard part do? From the bash manual: ${parameter:-word} If parameter is unset or null, the expansion of word is substituted. Otherwise, … Read more

Stop on first error [duplicate]

Maybe you want set -e: www.davidpashley.com/articles/writing-robust-shell-scripts.html#id2382181: This tells bash that it should exit the script if any statement returns a non-true return value. The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. Again, for readability you may want to use set -o errexit.

How does one output bold text in Bash?

The most compatible way of doing this is using tput to discover the right sequences to send to the terminal: bold=$(tput bold) normal=$(tput sgr0) then you can use the variables $bold and $normal to format things: echo “this is ${bold}bold${normal} but this isn’t” gives this is bold but this isn’t