#!/usr/bin/env etsh : : etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: 355855a07fb32cc51f963717a53a67f45cc4f2eb $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " Get the HTTP/FTP/FILE header from the specified URL w/ curl(1). " : " If `-f' is specified, getheader follows HTTP redirects. " : " If `-h' is specified, getheader prints usage message. " : : " usage: getheader [ [-f] URL | [-h] ] " : : " Check for correct usage. " : >>$0'' <'' ; : >>$1'' <'' ; : >>$2'' <'' ; killer $0 getheader if $# != 2 -a X$1 = X-f goto Usage if $# = 1 -a X$1 = X-h goto Usage if $# = 1 -a X$1 != X goto CheckOne if $# = 2 -a X$2 != X -a X$1 = X-f goto CheckTwo : Usage if { exit } pusage $0 '"[ [-f] URL | [-h] ]"' : CheckOne echo $1 | grep '^-' >/dev/null if $? = 0 goto Usage echo $1 | egrep -i '^(file|ftp|http|https)://([0-9a-z]|[^-])' >/dev/null if $? != 0 if { exit } perror $0 $1'": Invalid URL"' goto Continue : CheckTwo echo $2 | egrep -i '^(file|ftp|http|https)://([0-9a-z]|[^-])' >/dev/null if $? != 0 if { exit } perror $0 $2'": Invalid URL"' : fallthrough : Continue - " Error exit if which is not found, fails, or curl is not found. " trap : 2 3 if ! { fd2 which which >/dev/null } if { exit } perror $0 '"which: Not found"' if { fd2 which . >/dev/null } if { exit } perror $0 '"which: Invalid results"' if ! { fd2 which curl >/dev/null } if { exit } perror $0 '"curl: Not found"' trap - 2 3 : " Invoke curl to do the work. " if $# = 1 if { exit } curl --fail --head --silent --show-error $1 if $# = 2 if { exit } curl --fail --head --location --silent --show-error $2