The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check for a particular character inside a file and substitute with a given character? karthikprasathk AIX 1 07-01-2008 12:29 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 12:18 PM
Processing extended ascii character file names in UNIX (BASH scipts) peli UNIX for Advanced & Expert Users 9 04-06-2008 02:17 PM
Non-ascii character detection (perl or grep) srinivasan_85 UNIX for Dummies Questions & Answers 9 02-20-2007 05:38 AM
ASCII character to accept logon password gord UNIX for Dummies Questions & Answers 8 02-02-2006 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 09-10-2008
Registered User
 

Join Date: Dec 2007
Location: Denver
Posts: 16
Quote:
Originally Posted by Ygor
Interesting. From info printf...
Quote:
* If the leading character of a numeric argument is `"' or `'' then
its value is the numeric value of the immediately following
character. Any remaining characters are silently ignored if the
`POSIXLY_CORRECT' environment variable is set; otherwise, a
warning is printed. For example, `printf "%d" "'a"' outputs `97'
on hosts that use the ASCII character set, since `a' has the
numeric value 97 in ASCII.
Quote:
Originally Posted by fpmurphy
From POSIX.1-2001 ..
Quote:
The argument operands will be treated as strings if the corresponding conversion character is b, c or s; otherwise, it will be evaluated as a C constant, as described by the ISO C standard, with the following extensions:

* If the leading character is a single- or double-quote, the value will be the numeric value in the underlying codeset of the character following the single- or double-quote.
Both of these seem to answer my question. None of the man pages (on Solaris 10) explained this with this kind of detail. Thank you.
Reply With Quote
Forum Sponsor
  #9  
Old 09-10-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 568
Quote:
If the leading character of a numeric argument is `"' or `'' then
its value is the numeric value of the immediately following
character. Any remaining characters are silently ignored if the
`POSIXLY_CORRECT' environment variable is set; otherwise, a
warning is printed. For example, `printf "%d" "'a"' outputs `97'
on hosts that use the ASCII character set, since `a' has the
numeric value 97 in ASCII.
The printf() manpage on AIX doesn't have this information. The flip side is whether printf() checks for the terminating single-tick to ensure that it's a character. On AIX something like this outputs the decimal value of 'A' in the ASCII character code alongwith an error message. So just for grins what would be its output on your machine???

Code:
printf "%d\n" "'AB"
printf: 3016-002 'AB is not completely converted.
65
Reply With Quote
  #10  
Old 09-10-2008
Registered User
 

Join Date: Dec 2007
Location: Denver
Posts: 16
Quote:
Originally Posted by shamrock View Post
Code:
printf "%d\n" "'AB"
printf: 3016-002 'AB is not completely converted.
65
Virtually identical to yours...
Code:
printf "%d\n" "'AB"
printf: 'AB not completely converted
65
Reply With Quote
  #11  
Old 09-10-2008
Registered User
 

Join Date: Dec 2007
Location: Denver
Posts: 16
Actually, I just found this out.

In csh and ksh the output is as I've shown above. However, in bash it's this...
Code:
printf "%d\n" "'AB"
65
Reply With Quote
  #12  
Old 09-10-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
If Perl is acceptable, it offers the ord() function for returning the character code of a single character. When invoked on a multi-character string, it simply returns the character code of the first character of the string.

Code:
perl -le 'print ord(shift)' A
Reply With Quote
  #13  
Old 09-10-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 568
Quote:
Originally Posted by sszd View Post
Actually, I just found this out.

In csh and ksh the output is as I've shown above. However, in bash it's this...
Code:
printf "%d\n" "'AB"
65
On HP-UX it outputs the ASCII value of the character but no errors that is the same as in bash for the o/p.
Code:
printf "%d\n" "'AB"
65
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0