Script using sed adds an “e” to the output files
I have a script that adds a new user and creates a virtual host for the users domain name. The script works great with one exception... in /etc/apache2/sites-available/ all of my virtual host files have two copies, one with an e and one without.
I believe my issue lies when I use the SED command. Can I get a second opinion?
Here is the script:
# 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.."
scripts
add a comment |
I have a script that adds a new user and creates a virtual host for the users domain name. The script works great with one exception... in /etc/apache2/sites-available/ all of my virtual host files have two copies, one with an e and one without.
I believe my issue lies when I use the SED command. Can I get a second opinion?
Here is the script:
# 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.."
scripts
3
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44
add a comment |
I have a script that adds a new user and creates a virtual host for the users domain name. The script works great with one exception... in /etc/apache2/sites-available/ all of my virtual host files have two copies, one with an e and one without.
I believe my issue lies when I use the SED command. Can I get a second opinion?
Here is the script:
# 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.."
scripts
I have a script that adds a new user and creates a virtual host for the users domain name. The script works great with one exception... in /etc/apache2/sites-available/ all of my virtual host files have two copies, one with an e and one without.
I believe my issue lies when I use the SED command. Can I get a second opinion?
Here is the script:
# 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.."
scripts
scripts
edited Jul 4 '11 at 20:25
Jorge Castro
36.8k106422617
36.8k106422617
asked Jul 4 '11 at 17:36
jason.dot.hjason.dot.h
13338
13338
3
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44
add a comment |
3
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44
3
3
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44
add a comment |
1 Answer
1
active
oldest
votes
You need separate -i and -e arguments to sed. -ie is telling sed to create a backup file with an 'e' appended.

To fix, just replace the sed invocation above to:
sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f51775%2fscript-using-sed-adds-an-e-to-the-output-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need separate -i and -e arguments to sed. -ie is telling sed to create a backup file with an 'e' appended.

To fix, just replace the sed invocation above to:
sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
add a comment |
You need separate -i and -e arguments to sed. -ie is telling sed to create a backup file with an 'e' appended.

To fix, just replace the sed invocation above to:
sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
add a comment |
You need separate -i and -e arguments to sed. -ie is telling sed to create a backup file with an 'e' appended.

To fix, just replace the sed invocation above to:
sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
You need separate -i and -e arguments to sed. -ie is telling sed to create a backup file with an 'e' appended.

To fix, just replace the sed invocation above to:
sudo sed -i -e "s/NEWUSERNAME/$username/" /etc/apache2/sites-available/$newdomain
edited 26 mins ago
Chris Schmitz
1054
1054
answered Jul 5 '11 at 2:39
Jeremy KerrJeremy Kerr
19.5k34058
19.5k34058
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
add a comment |
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
Although you've got a comment with this, I've adding the details as an answer for completeness.
– Jeremy Kerr
Jul 5 '11 at 2:40
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
When I first read this answer I understood what it was saying but didn't immediately grasp why the e was being taken as the suffix. I then checked the manual page and realized the i takes an optional argument. It makes this answer obvious in retrospect but it took me a second to understand the why (hence the image add).
– Chris Schmitz
2 hours ago
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f51775%2fscript-using-sed-adds-an-e-to-the-output-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Sorry, after typing that I realized my mistake, when using the SED command I had the -i option to edit the file "inline" without creating the copy. For some reason I added the e command as well, which is supposed to add the script. I changed the -ie to -i and the script works as needed. I cannot answer my own question yet so I added a comment.
– jason.dot.h
Jul 4 '11 at 17:44