sed를 사용하는 스크립트는 출력 파일에“e”를 추가합니다


18

새 사용자를 추가하고 사용자 도메인 이름에 대한 가상 호스트를 생성하는 스크립트가 있습니다. 스크립트는 / etc / apache2 / sites-available /에서 하나의 예외로 훌륭하게 작동합니다. 모든 가상 호스트 파일에는 두 개의 사본이 있습니다. 하나는 e이고 다른 하나는 없습니다.

SED 명령을 사용할 때 문제가 있다고 생각합니다. 다른 의견을 얻을 수 있습니까?

스크립트는 다음과 같습니다.

# set the working directory
dir=$(pwd)

# request the new domain name
printf "Enter the new domain name, without the www (i.e newdomain.com):\n"
read newdomain

# request the new username
printf "Enter the new username (i.e newusername):\n"
read username

# create the new user
sudo adduser $username

# copy the virtual host to sites-available
sudo cp /templates/domain-vhost /etc/apache2/sites-available/$newdomain

# echo results
echo "Successfully created the virtual host file at: /etc/apache2/sites-available/$newdomain.."

# change the domain name in the virtual host file
sudo sed -ie "s/NEWDOMAINNAME/$newdomain/" /etc/apache2/sites-available/$newdomain

# echo results
echo "Modified the virtual host to reflect the new domain: $newdomain.."

# change the directory path in the virtual host
sudo sed -ie "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain

# echo results
echo "Successfully modified the new virtual host file.."

# enable the site with apache
cd /etc/apache2/sites-available/
sudo a2ensite $newdomain

# echo results
echo "Successfully enabled the $newdomain.."

# change to previous working directory
cd $dir

# reload apache
sudo /etc/init.d/apache2 reload

# notify user of action
echo "Finished creating the new domain, $newdomain, and restarted Apache.."

3
죄송하지만, 실수를 입력 한 후 SED 명령을 사용할 때 사본을 만들지 않고 "inline"파일을 편집하는 -i 옵션이있었습니다. 어떤 이유로 스크립트를 추가 해야하는 e 명령도 추가했습니다. -ie를 -i로 변경하면 스크립트가 필요에 따라 작동합니다. 아직 내 질문에 대답 할 수 없으므로 의견을 추가했습니다.
jason.dot.h

답변:


17

별도의 필요 -i-e나오지도에 인수. -iesed에 'e'가 추가 된 백업 파일을 만들도록 지시하고 있습니다.

<code> -i </ code> 수동 입력

수정하려면 위의 sed 호출을 다음과 같이 바꾸십시오.

sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain

이에 대한 의견이 있지만 세부 사항을 완성도에 대한 답변으로 추가했습니다.
Jeremy Kerr

내가이 답을 처음 읽었을 때 나는 그것이 무엇을 말하는지 이해했지만 e가 왜 접미사로 취해지고 있는지 즉시 파악하지 못했습니다. 그런 다음 매뉴얼 페이지를 확인하고 선택적 인수를 취하는 것을 깨달았습니다. 이 대답은 회고 적으로 명확하게하지만 이유를 이해하는 데 잠시 시간이 걸렸습니다 (따라서 이미지가 추가됩니다).
Chris Schmitz
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.