On 29-05-2011 12:44:46 +0200, Christopher Schwan wrote:
> Thank you for that script. I experimented a bit with it and have a number of
> corrections and suggestions:
>
> - alias does not work because my_sed is not declared at this stage. I removed
> the whole alias line because I want to selectively enable my_sed
> - oargs must be an array in order to make quoting work:
>
> local oargs=( "${@}" )
>
> - In the ewarn line ${oargs} should be changed to ${nargs[@]} (!?)
> - is it correct to treat -e and -f alike ? I am not sure about that, because
> the latter expects a file
Yes, because (also in your function) you always shift, and assume the
next argument is there. Hence, you have two identical cases in your
script now. I only distinguised between 1) being able to do something
(-i) and 2) having a pattern to work with (-e/-f or first non-option
argument as string pattern).
> - If no "-e" is given, the first non-option argument is treated as the sed-
> script-expression, therefore I added hade=yes in the if-branch
That one was missing indeed. I just quickly wrote the proof of concept
:)
> The new function now reads:
>
[snip improved function]
>
> As you can see, I added support for long-options. However, testing the
> individual sed commands remains to be done. This could be especially
> difficult
> if input is taken from stdin (e.g. in cat foo | sed "s:a:b:g").
You might be able to detect input is a pipe, and temporarily
write the input to some file, then perform the sed without the -i
requirement and remove the temp file after the real sed.
> I tested my_sed within our sage ebuild[1]. This ebuild contains 39 sed
> commands and I was able to spot one useless sed.
Cool, nice to see you've made it into something useful!
> [1] https://github.com/cschwan/sage-on-gentoo/blob/master/sci-
> mathematics/sage/sage-4.7.ebuild
--
Fabian Groffen
Gentoo on a different level