I want to extract the host name of a machine and omit whatever exists after .
. For example, the command hostname
says compute-0-0.local
. So, I used `cut command like this
# hostname | cut -f 1 -d "."
compute-0-0
Now, I want to put that output in a variable. The following command doesn't work.
# HT=`hostname` | cut -f 1 -d "."
# echo $HT
compute-0-0.local
Any way to fix that?
$()
over backticks. see @clk 's answer for details on how. – ctrl-alt-delor Jul 18 '16 at 17:35"${HOSTNAME%%.*}"
work for you?HOSTNAME
is not in POSIX though – iruvar Jul 18 '16 at 18:00hostname
command), you could just usehostname -s
akahostname --short
. – cas Jul 19 '16 at 11:57