tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ How to pass back the array value?

What is the bash syntax for [[ ]] - and how to find in "man bash" ? ▻

problems using printf !!

In article <qljt4.25$I31.1044@burlma1-snr2>,
Barry Margolin  <barmar@bbnplanet.com> wrote:
>>$ printf "${string}\n"
>
>The first argument to printf is supposed to be a format string, which may
>contain various % and \ escapes, which are treated specially.  What you
>should do is:
>
>printf "%s\n" "$string"

But Jake *wants* \ escapes to be processed in his string!  (This
information was spread over two articles, so it was easy to miss.)

The problem is that the `\x' escape takes 1 to 3 hex digits.  (Why 3?
I've no idea: 2 or 4 make more sense to me.)  It is interpreting `\x2Fc'
as a single character specification: apparently it is chopped down to 8
bits and you end up with "latin small letter u with diaresis" in the ISO
8859-1 character set.

Personally I would abandon trying to use printf(1) to do this.  Apart
from anything else, not all versions of printf(1) support `\xHHH'
character escapes.  (Thanks guys!  Having destroyed echo(1) with your
gratuitous incompatibilities, why don't you go for printf(1) next?  With
a bit of effort, you could make it impossible to print anything at all
from a portable shell script!)

Real's sed solution looks good to me.

Tim.
--
Tim Goodwin   | "If you don't know what closures are, you probably don't
Leicester, UK | want to know what closures are." -- Larry Wall

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: problems using printf !!
Date: 25 Feb 2000 13:28:37 -0000
Message-ID: <89602r$3d3$1@ltpcg.star.le.ac.uk>
References: <893h0l$pmq$1@nnrp1.deja.com> <893nb8$una$1@nnrp1.deja.com>
  <qljt4.25$I31.1044@burlma1-snr2>

△ comp.unix.shell △

◅ How to pass back the array value?

What is the bash syntax for [[ ]] - and how to find in "man bash" ? ▻