I can't get my function to do what I want. When I call my function get_from_A_to_F I give it an argument $remainder. I want my function to substitute a number higher than 9 to a specific letter. If the argument is equal to 10 than it should change it to "A". However it still leaves it as a 10. What am I doing wrong here?
#!/bin/sh
get_from_A_to_F()
{
case $1 in
10) $1="A"
;;
11) $1="B"
;;
12) $1="C"
;;
13) $1="D"
;;
14) $1="E"
;;
15) $1="F"
;;
[0-9]) $1=$1
;;
esac
echo $1
}
read number
string=""
index=`expr index $number "."`
if [ $index -eq 0 ]
then
integer=$number
fraction=0
else
integer=`expr substr $number 1 $(expr $index - 1)`
fraction=`expr "$number - $integer" | bc`
fi
result=$integer
while [ $result -ne 0 ]
do
remainder=`expr $result % 16`
get_from_A_to_F $remainder
result=`expr $result / 16`
string=$remainder$string
done
Current output(if number read is 634):
634
test: 43: 10=A: not found
10
test: 43: 7=7: not found
7
test: 43: 2=2: not found
2
set -xwill show cmds with substituted variable values.set -vxshows current command or block (can be confusing at first) + the substituted variable values. Put one of those just at the top of your function, and you can turn the same off withset +x OR set +vx. Then you'll be able to see what is happening inside your script. (try eval again, either I don't understand what you're trying to achieve, or something is wonky). Also please edit you Q to include sample usage with expected output and current output. Good luck.