On 24.06.2012 10:19, Janis Papanagnou wrote:
On 24.06.2012 09:33, Janis Papanagnou wrote:
From: [email protected]
$ print $(( '_' )) $(( ':' ))
95 58
I wasn't aware that we can get the ordinal numbers of characters that way.
Thanks!
In cases where I am looking for the other way round, getting the character
from its ordinal number, I intuitively always first try (though to no avail)
printf "%c%c\n" 95 58
As a workaround I still resort to
$( echo 95P | dc )
$( echo 58P | dc )
Is there a simple *builtin* way for the other way round, get the character
from its ordinal number? I seem to recall there was, but don't remember.
typeset -i8 c=95
printf "\\${c#*#}\n"
Thanks. But I fear this needs some explanation; e.g. why does changing the base
from 8 to 12 (or 10 or 2) make that fail (and even fail in different ways)?
Why need hte base definition at all? And what's the semantics of the '\\' in
this context; printf --man seems to not explain that? Mind to elaborate?
printf octal escapes are specified by POSIX:
3. In addition to the escape sequences […], "\ddd", where ddd is
a one, two, or three-digit octal number, shall be written as a byte with
the numeric value specified by the octal number.
ksh93 also supports hexadecimal escapes in the form of \xdd.
Regarding %c I don't really know.
--
Guido Berhoerster
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users