I am using /etc/host to map localhost to a web domain. I would like a fast way of doing this rather than searching and replacing every time. I put this in my .bashrc file.
alias hostchange=' nowdir=$PWD; cd /etc; mv hosts hoststempname; mv hostssecondary hosts; mv hoststempname hostssecondary; cd $nowdir'
I am getting this error and it won't progress regardless y or n.
mv: rename hosts to hoststempname: Permission denied override rw-r--r-- root/wheel for hosts? (y/n [n])
I got it to work by adding sudo.
alias hostchange=' nowdir=$PWD; cd /etc; sudo mv hosts hoststempname; sudo mv hostssecondary hosts; sudo mv hoststempname hostssecondary; cd $nowdir'
Is this legitimate, I'm taking a shot in the dark here?