On 09/17/13 13:49, Craig R. Skinner wrote:
On 2013-09-16 Mon 23:28 PM |, Alexander Hall wrote:
sed can do it all. Really.
This is getting beyond me Alexander.....
Is sed a mechanism to step away from using file(1) ?
Heh, sorry about that. :)
Nah, it's merely a way to combine `head | grep | sed | cut | ...` pipes
since sed is often capable to cope with it all.
Notes:
- I separate re_quote() cause I think it can be useful in other places.
- I think re_quote() is (basic) regex complete.
- I don't care if the interpreter is (or seems) nonexistant, as that
shouldn't be a runtime error.
- I'm sure sed may die horribly if you try to feed it a 9GB oneline
file. However, if so, it should not produce any output anyway. ;)
If this would ever be considered a real problem, dd(1) would help
(as espie already mentioned).
re_quote() { sed 's/\([]^$*.\\[]\)/\\\1/g'; }
interpreter=$(
sed -n 's/^#![[:space:]]*\(.*\)/\1 /p;q' "${daemon}" |
In this case I make sure sed only looks at the first line (unconditional
'q'uit at the end), and prints it, followed by a space, but only if it
was able to withdraw a shebang and optional following whitespace from
the start of the line (-n, s/^...\(.*\)/\1 /p).
What is known and discussed though, is that sed could potentially crash
on a *really* long first line in that file. In this case, a pre-check
with file(1), or input truncation with dd, would help.
Anyway, my $.02 is running out, so I leave it up to the rc.d
maintainer(s) to determine if they consider it a real problem or if it
can go the way of the hash-collision discussion...
/Alexander
re_quote)
pexp="$interpreter$pexp"
Moreover,
- you probably want to unset $interpreter when done.
- we might want to re_quote the entire $pexp later instead.