bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Avoid unportable nested double-quotes and backquotes.


From: Bruno Haible
Subject: Re: Avoid unportable nested double-quotes and backquotes.
Date: Sun, 23 May 2010 13:37:41 +0200
User-agent: KMail/1.9.9

Hi Ralf,

> noticed this small shell unportability in gnulib coming from gettext.
> ...
>          ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
> -        ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
> +        ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'`

There is no unportability here. I tested these statements

   ac_dir=./foo
   ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
   echo "$ac_dir_suffix"
   ac_dir=b/foo
   ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
   echo "$ac_dir_suffix"

and got the same result in bash, ksh, zsh, dash, /bin/sh on Solaris
and other systems, and pdksh 5.2.14 (= /bin/sh on OpenBSD 4.5) (without
and with 'set -o posix').

I think you must be referring to
  
<http://www.gnu.org/software/autoconf/manual/html_node/Shell-Substitutions.html>
It says
  "not all shells properly understand "`..."..."...`". Worse yet, not all
   shells understand "`...\"...\"...`" the same way. There is just no portable
   way to use double-quoted strings inside double-quoted back-quoted
   expressions"
but it does not go into details about which shells are affected.

Or you may be referring to
  <http://www.gnu.org/software/autoconf/manual/html_node/Shellology.html>
section "Pdksh". With the /bin/sh on OpenBSD 4.5, which identifies itself as
  $ echo $SH_VERSION
  @(#)PD KSH v5.2.14 99/07/13.2
I can reproduce the problem mentioned in that doc, but I cannot reproduce a
problem with the above statements.

Some more tests with this shell:

  $ echo \a\t\.\"abc\"\[\]
  at."abc"[]                               (regardless of POSIX mode)

  $ var="`echo \a\t\.\"abc\"\[\] > j`"
  $ cat j
  at.abc[]                                 (in default mode)
  at."abc"[]                               (in POSIX mode)

  $ var=`echo \a\t\."abc"\[\] > j`
  $ cat j
  at.abc[]                                 (regardless of POSIX mode)

  $ var=`echo \a\t\.\"abc\"\[\] > j`
  $ cat j
  at."abc"[]                               (regardless of POSIX mode)

As you can see, the only problem is with the use of \" inside backquote inside
double-quote.

In summary, I did find a shell that does not understand "`...\"...\"...`"
but I did not find a shell that does not understand "`..."..."...`". That
paragraph in autoconf.texi dates back to 2000-05-19 12:17:29. It may have
referred to shells that were in common use between 1995 and 2000 and have
disappeared by now.

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]