/trunk/root/usr/bin/modunreg

johnbock

Mitglied
Mitglied seit
2 Mrz 2008
Beiträge
310
Punkte für Reaktionen
0
Punkte
0
Code:
content=$(grep -v "^$2|" /mod/etc/reg/cgi.reg) 
echo "$content" > /mod/etc/reg/cgi.reg

sed can solve these types of things pretty elegantly
Code:
sed -i "/^$2|/d" /mod/etc/reg/cgi.reg
 
That appears even better, but it imposes the problem of / being part of some of the arguments to modunreg. When changing to
Code:
sed -i "\@^$2|@d" /mod/etc/reg/cgi.reg
the problem of the @ (or any other character other than /) being allow in unix filenames arises.
So to get it 100% correct, the arguments would have to be escaped before being fed to sed, right? Or do you see another solution?
 
If you really want to get tricky you could use an ascii control symbol: something under decimal 32...
 
That would be hardly maintainable. If the busybox sh would do some of the fancy substitutions bash does, we could do something like
Code:
sed -i "\@^${2//\//\\\/}|@d" /mod/etc/reg/cgi.reg
:-).

I don't think we should drop the support for / in arguments we have now, and we should try to avoid implementing other pitfalls. But maybe picking some other character that's unlikely to be used in arguments may be ok?
 
I'm not sure about that, I find the following not too hard to read
Code:
nil=$(echo -ne '\01')
sed -i "\\${nil}^${2}|${nil}d" /mod/etc/reg/cgi.reg
but if you do insist, I would suggest using star or ampersand.
 
Your proposal looks good. I didn't think of using a variable for the special character. I implemented this in r2093.
 
looks good, should we put that in a best practices/howto and link it into the style guide?
 
Kostenlos!

Statistik des Forums

Themen
248,917
Beiträge
2,305,038
Mitglieder
378,638
Neuestes Mitglied
Patrick89