Jump to content

Echoing the integer-value of a character


Recommended Posts

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...