satelliteuser083 Posted January 18, 2008 Report Share Posted January 18, 2008 (edited) I'd like to echo the interger-value of single characters entered via stdin; in pascal I'd write something like: print int(inchar) but I can't find the bash-script equivalent of 'int'. Can anyone help? Thanks. Edited January 18, 2008 by satelliteuser083 Quote Link to comment Share on other sites More sharing options...
tyme Posted January 18, 2008 Report Share Posted January 18, 2008 bash doesn't support variable types. in bash, all variable are essentially character strings. as far as how to do what you're looking to do, I'm not really sure... Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 19, 2008 Report Share Posted January 19, 2008 Easy one: read var1 echo $var1 Quote Link to comment Share on other sites More sharing options...
neddie Posted January 19, 2008 Report Share Posted January 19, 2008 That just returns the character here. What I think he wants is the character code, the ascii value of the character entered. But I don't know how to answer it, sorry. Quote Link to comment Share on other sites More sharing options...
satelliteuser083 Posted January 19, 2008 Author Report Share Posted January 19, 2008 Yes, neddie, that is what I wanted and your suggestion does only return the character, steve. Thanks, nevertheless. As it happens, I've managed to solve my problem another way, so knowing the value is unimportant. What is bugging me at the moment is the following: I want to return one of three possible values from a script back to its caller, using "return result_value" but get the message can only `return' from a function or sourced script Can one of you tell me what "sourced script" means, and, possibly, how to overcome the problem. Thanks Quote Link to comment Share on other sites More sharing options...
satelliteuser083 Posted January 20, 2008 Author Report Share Posted January 20, 2008 I stumbled across the following on http://www.webservertalk.com/message1585326.html ; and it does exactly what I need. : :P ord() { if [[ $1 ]] then echo "$(od -td1 <<<"$1" | awk 'NR==1{print $2}')" else exit 1 fi } for i do for ((j=0; j < ${#i}; ++j)) do ch=${i:$j:1} dec=$(ord "$ch") echo -e "char: '$ch'\t ord: $dec" done done Great stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.