Re: shell scripting advise: Don't use backslashes inside backtick quotes



On Thu, Aug 04, 2005 at 07:31:42AM +0200, Oswald Buddenhagen wrote:
> On Thu, Aug 04, 2005 at 01:19:50AM +0200, Roland Illig wrote:
> > quote() {
> > 	_sedexpr="s,','\\\\'',g"
> >         _quotestr=`echo x"$1" | sed -e '1s,^x,,' -e "${_sedexpr}"`
> >         echo "'${_quotestr}'"
> > }
> > 
> > So if you ever use backticks, please don't use backslashes inside them.
> > 
> yes, it's a well-known ;) fact that backticks have weird semantics when
> it comes to about any other nested quoting.
> really old shells will explode on your current version, too, but we
> really needn't to consider those.
> 
more importantly ... unless $1 is guaranteed not to contain backslashes,
things will go awfully wrong with some echo variants. safest is 'printf
"%s" "$1"' - supposedly all halfways modern systems have it ...
otherwise you could try to inject it by putting it into a sed i
statement, but i have no clue whether/how that works.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]