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

Oswald Buddenhagen wrote:
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() {
       _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.

Why? Because of possible backslashes?

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.

Thanks for that comment. I almost forgot. Shell programming is ugly. :(


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