Subject: Re: echo weirdness
To: Patrick Welche <prlw1@newn.cam.ac.uk>
From: Andreas Kahari <ak+netbsd@freeshell.org>
List: current-users
Date: 02/18/2004 14:29:01
On Wed, Feb 18, 2004 at 01:55:07PM +0000, Patrick Welche wrote:
> On Wed, Feb 18, 2004 at 12:04:08AM +0000, David Laight wrote:
> > Fot portability use printf(1) - which is a builtin in netbsd /bin/sh.
> 
> There I was surpised that printf "%c" 65 gets me 6, not A, but it is
> what it says in the man page.. any idea how to do int <-> char conversion
> in a script?

Using awk:

    i=65; awk -v i=$i 'BEGIN { printf "%c", i }'

Using decimal->octal conversion, and then getting the
corresponding character...

    i=65; printf "\\$(printf "%o" $i)"

-- 
Andreas Kähäri                      |][][|
                                    |[][]|
East Anglia                         |][][|
England                             |[][]|