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
#echo $string
done
Note : when you are inside your function, "$1" refers to the first argument passed to your function (and not the first argument given to your shell script).