Add address at end of line in hosts file using sed

后端 未结 1 936
遇见更好的自我
遇见更好的自我 2021-01-14 14:46

I have a specific line in the hosts file that is used for my local Wordpress Multisite install, which looks like this:

127.0.0.1       localhost domain.dev s         


        
相关标签:
1条回答
  • 2021-01-14 15:45

    if this is the line 7

    sed -i '.bak' "7 s/$/ ${site_addr}.domain.dev/" /etc/hosts
    

    but you can use the pattern matching (a bit safer) with

    sed -i '.bak' "/127\.0\.0\.1/ s/$/ ${site_addr}.domain.dev/" /etc/hosts
    

    i recommand to also first check if the domain is not already in

    0 讨论(0)
提交回复
热议问题