Jump to content

Echoing the integer-value of a character


Recommended Posts

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...

Link to comment
Share on other sites

Yes, neddie, that is what I wanted and your suggestion does only return the character, steve. Thanks, nevertheless. :thumbs:

 

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

Link to comment
Share on other sites

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. :thumbs:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...