Creative Commons

2007-10-11 11:49:10

Stupid Literalness

I've stepped into something new... trying to create a very custom live cd. There are tools, specifically Revisor, that let you create a custom Fedora live cd. While a good idea, it kind of sucks cause nothing works right. But that aside, I didn't want a custom live cd, I wanted a very custom live cd. Basically, these programs will let you choose what default packages you want on your cd along with setting other options (the part that doesn't work). I, however, wanted to add software to the cd that isn't in the default repos, add users, change files, etc.
All of this stuff warranted the use of many console commands, all of which I have never used the way I needed to for this project. Commands like useradd, echo, passwd, etc. are normal everyday commands, but I've never needed to automate them, that is, make them work without user input. So I needed to have useradd create a user. I executed
# useradd --help
and was greeted with the help file for useradd. Great. Now that command is good. Then I needed to have the script set the password, without my input, for the new user. I executed
# passwd --help
and got help for passwd. Woohoo. But then I needed to wipe a file and put new, multiline, contents into it. My original command was [something like]
# echo "[section]\nstuff for line 1" > /etc/myfile
which made the contents of /etc/myfile
[section]\nstuff for line 1
Stupid echo taking my line literally. Obviously I wanted there to be two lines to that file, not just one with a literal newline character. So I needed to find out how to tell echo to stop taking me literally.
# echo --help --help


Post a comment!