I'm currently working on making a text file of the whole process of setting up my server for my normal usage.
And would like to know if there is any way to write a shell script so that I can make the "nano" insert content, save it, exit it, and then continue with the rest of my commands.
Cause when I put all of this into the shell script:
sudo nano /etc/apache2/conf-available/fqdn.conf
ServerName localhost
sudo a2enconf fqdn
Then it shows the "nano" file editor with this content:
ServerName localhost
sudo a2enconf fqdn
Well, while I wanted it to save and exit after the ServerName localhost
, so that my script could continue.
Would that be posibble anyhow?
Best Answer
I may have misunderstood your question. SHH doesn't exist, do you mean SH or SSH? Or maybe Bash? (EDIT: brought an edit to fix this)
Anyway,
nano
won't be much of assistance here.echo
will.The above shell code will send your text into the file. Replacing
>
with>>
will append it instead, if that's what you're looking for.If you need root privileges to write to this file, then use
tee
instead of a simple shell redirection (>
/>>
). This will allow you to usesudo
properly:nano
is here so that you, the user, can write data manually into a file. However, if you're looking for an automated process, there's no need for an editor, coreutils can handle that just fine. Linux doesn't need the fancynano
interface to write into a file.