help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Reading and handling "control" characters from a file


From: Chet Ramey
Subject: Re: [Help-bash] Reading and handling "control" characters from a file
Date: Sat, 21 Apr 2012 14:13:52 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20120327 Thunderbird/11.0.1

On 4/19/12 6:11 PM, Conrad J. Sabatier wrote:
> I've just started doing a little prototyping in bash for a program I'll 
> eventually code most likely in C, and have hit a serious stumbling block 
> re: the handling of characters (bytes) in the very low range of the ASCII 
> table.

Bash variables are strings of characters.  There is a difference between
a character with ASCII value 4 and a character with the ASCII value 52
("4").  Shell arithmetic convers the latter into numbers using the
equivalent of strtol() before use.

To make what you want work, you'll have to figure out some way to offset
the value you read from the file (i.e., c+'0') before attempting to use it
in an arithmetic context.  Maybe perl or something like that could help.
It's quite difficult to do using just what the shell provides.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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