2

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

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

How I can put output of hostname in echo string?

PS

I do not want to create bash script.

2

Simply do:

echo "127.0.0.1 $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 "127.0.0.1 $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.