I am trying to create a dev host file like below -

$sudo echo " ramratan-pc" >> /etc/hosts

How I can put output of hostname in echo string?


I do not want to create bash script.


Simply do:

echo " $HOSTNAME" | sudo tee -a /etc/hosts
  • 1
    I think he wants $HOSTNAME instead of specifying the hostname. – user508889 May 5 '16 at 20:08
  • 2
    edited the answer, just had to look up the variables – Videonauth May 5 '16 at 20:12
  • sudo echo " $HOSTNAME" >> /etc/hosts works for me. Thank you @Videonauth – Ramratan Gupta May 5 '16 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.