I know this is a simple question, but I can't recall a method of doing it. I wrote a service using automator to copy the public URL of a file in my Sites folder. I wrote this script:
sed -e 's/:/\//g' -e 's/\ /%20/g' -e "s/^\/Users\/$USER\/Sites/http:\/\/$HOST\/~$USER/g" | pbcopy
But $HOST only has my computer's name, not including the domain. I figured out that I can do this:
host $HOST
myname.mydomain.com has address 111.111.111.111
I know I can use this to pull the domain name out:
set FULLHOST=`host $HOST | perl -pne 's/ has address .*//;$_=lc'`
sed -e 's/:/\//g' -e 's/\ /%20/g' -e "s/^\/Users\/$USER\/Sites/http:\/\/$FULLHOST\/~$USER/g" | pbcopy
but I'm curious, is there a cleaner command that will just give me back either the domain (mydomain.com) or the full address (myname.mydomain.com)?
Best Answer
There’s
/bin/hostname
which prints the name of the machine, either including the domain (which is the default mode of operation) or without it. (I couldn’t verify that it really does that because I have no idea where to configure the domain name of my machine. :)