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-0Now, I want to put that output in a variable. The following command doesn't work.# HT=`hostname` | cut -f 1 -d .# echo $HTcompute-0-0.localAny way to fix that?
Using cut command for an environment variable
environment variables;cut
Use this instead, noting that your entire command must be enclosed within the backticks:HT=`hostname | cut -f 1 -d .`You could potentially use $() as well:HT=$(hostname | cut -f 1 -d .)This syntax for command substitution is not supported in certain shells, though, including the original Bourne shell, csh and tcsh. For those shells you will need to use backticks. 