bash syntax


Subject: bash syntax
bryan@ak.net
Date: Fri Mar 29 2002 - 21:07:58 AKST


I've got a question only a bash guru can answer. Fair warning --
this is rather esoteric, so most of you can just 'delete' now.

There's a command I like to use as a filter to escape single
quote marks from shell interpretation. I use it so infrequently
that each time I want it, I have to spend 5-10 minutes getting
all the characters in the right place. So I decided I'd put it
in an alias, or a simple shell script, to always have it available.

First, I tried to alias the word quote to exactly the following:
sed "s/'/\\\'/g"
I tried a couple ways of putting the above in quotes, to make it
a single string for alias. The best way seemed to be to use double
quotes around the whole thing, and \ escape the existing two.
Try it. Where the hell are those extra quotes coming from?

Since that didn't work, I used a shell script, and it works nicely.
I'm only asking now out of curiosity. I have one more question --
in the original string, why is it neccessary to \ escape the second
quote, but not the first one?

I'm using bash 2.03.0(1), btw. If anyone's still reading at this
point, I challenge you to make sense out of it. :)

--
Bryan Medsker
bryan@ak.net



This archive was generated by hypermail 2a23 : Fri Mar 29 2002 - 21:10:38 AKST