Skip to contentSkip to conversation

Dash quoting bug?

DISCUSSION Herbert Xu 2 participants 2 messages Nov 30, 2007 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Herbert Xu

author
#1 lore raw
Quoted 4 lines · Eric Sunshine

According to the dash manual, within single quotes, all characters are treated as literals (except single quote), which appears to agree with POSIX, so the above behavior seems incorrect.

We need a patch for the dash manual :)

Unfortunately according to POSIX we must interpret these escape sequences:

12680 NAME
12681 echo - write arguments to standard output

12682 SYNOPSIS
12683 echo [string ...]

12684 DESCRIPTION
12685 The echo utility writes its arguments to standard output, followed by a <newline>. If there are
12686 no arguments, only the <newline> is written.

12687 OPTIONS

12688            The echo utility shall not recognize the "- -" argument in the manner specified by Guideline 10
12689            of the Base Definitions volume of IEEE Std 1003.1-200x, Section 12.2, Utility Syntax Guidelines;
12690            "- -" shall be recognized as a string operand.
12691            Implementations shall not support any options.

12692 OPERANDS
12693 The following operands shall be supported:

12694            string       A string to be written to standard output. If any operand is -n, it shall be treated as
12695                         a string, not an option. The following character sequences shall be recognized
12696                         within any of the arguments:
12697                         \a        Write an <alert>.
12698                         \b        Write a <backspace>.
12699                         \c        Suppress the <newline> that otherwise follows the final argument in the
12700                                   output. All characters following the '\c' in the arguments shall be
12701                                   ignored.
12702                         \f        Write a <form-feed>.
12703                         \n        Write a <newline>.
12704                         \r        Write a <carriage-return>.
12705                         \t        Write a <tab>.
12706                         \v        Write a <vertical-tab>.
12707                         \\        Write a backslash character.

12708 \0num Write an 8-bit value that is the zero, one, two, or three-digit octal number
12709 num.

I suggest that you switch over printf for portability. That is, replace all occurances of

echo "string"

with

printf "%s\n" "string

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 9 lines · Herbert Xu
Quoted 1 line · Eric Sunshine

According to the dash manual, within single quotes, all characters are treated as literals (except single quote), which appears to agree with POSIX, so the above behavior seems incorrect.

We need a patch for the dash manual :)
Unfortunately according to POSIX we must interpret these escape sequences:
12682 SYNOPSIS
12683 echo [string ...]
12695 The following character sequences shall be recognized
12696 within any of the arguments:
12703 \n Write a <newline>.

Thank you for the response and for pointing out this documentation.

Quoted 5 lines

I suggest that you switch over printf for portability. That is, replace all occurances of
echo "string"
with
printf "%s\n" "string

Unfortunately, in this case, a portability requirement to older platforms lacking 'printf' negates the viability of such a solution. As it turns out, however, I was able to resolve the issue by eliminating the need to emit backslashes, thus altogether side-stepping the problem.

-- ES