Grep is my enemy...

Michael Abbott michael at
Thu Oct 5 16:38:41 BST 2006

On Thu, 5 Oct 2006, Geraint Edwards wrote:
> Michael Abbott <michael at> said
>> It's rather a shame that [echo] fails if (and only if) $STRING
>> matches '^-[neE]+$': if anyone knows a more reliable method, please do
>> say!
> 	echo x"$STRING" | awk '{if(NR==1){sub(/^x/,"")}print}'
> 	echo x"$STRING" | awk 'NR==1{sub(/^x/,"")}{print}'


Cute, but hideous!

Have to confess I'm more of a sed fan than awk (really must learn awk one 
of these days), so I guess I'd write this as

 	echo x"$STRING" | sed 1s/.//

Hmm.  There's definitely a case for either a safeecho command or an 
extension to echo (patch to sh and bash) to support --.  Unfortunately 
neither of these would be standard and portable...

Hadn't actually though of doing this this way, but it looks like a 
practial workaround.

More information about the Ukfreebsd mailing list