Hey. I've always had the impression that ^ and $ were the end/begin anchor of the current pattern, and since e.g. grep/sed work normally in terms of lines the start/end of lines.
What I found a bit strange is that e.g.: printf '' | sed 's/^/foo/' printf '' | sed 's/$/foo/' printf '' | sed 's/^$/foo/' doesn't produce foo and that e.g. printf '' | grep '^' printf '' | grep '$' printf '' | grep '^$' printf '' | grep '*' don't match. Why? Or better said, which part of POSIX mandates this? Or is it simply "no stdin, nothing happens"? OTOH, other tools do operate on that: $ printf '' | wc 0 0 0 What looks IMO also a bit strange: $ printf 'f' | sed "s/$/foo/" foof $printf 'f' | sed "s/$/foo/" ffoo (with no newlines) So they do match, even though there is no \n character. OTOH $ printf 'f\n' | sed "s/$/foo/" foof $printf 'f\n' | sed "s/$/foo/" ffoo give the same, so while there clearly is a \n now (and thus I'd assume a new line) it's not matched. However: $ printf 'f\n\n' | sed "s/^/foo/" foof foo here it matches,... so it seems it would just ignore trailing non-\n-ended and empty lines, but NOT trailing (or only) non-\n-ended but non-empty lines . Seems a bit inconsequential. Any ideas? Thanks, Chris.
smime.p7s
Description: S/MIME cryptographic signature
