I'm trying to write a program that converts number bases. For example, when converting from base 10 to base 2, the input 5
will result in the output 101
.
This is my code:
#!/bin/sh
while read line
do
convert_base()
{
number=$1
inputbase=$2
outputbase=$3
echo "obase=$outputbase;ibase=$inputbase;$number" |bc
}
convert_base $1 $2 $3
echo $line >> $2
done < $1
This gives me a syntax error, though. How can I fix this?