Is it possible to Divide a negative number in bash script

I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error

basename: invalid option -- '5'
Try `basename --help' for more information.
(standard_in) 1: syntax error

The script is :

 #!/bin/bash
 for i in `cat ./eff_cal.txt`
 do
 some=`basename $i -lt`
 output=`echo $some*100/128 | bc -l`
 echo "`basename $i`---- $output" >> some.txt
 done

Is it possible by some way to divide negative numbers? It would be helpful if someone can give some pointers.

Lets say, ./eff_cal.txt has the input numbers.

Can you please explain some=`basename $i -lt` ????

I am taking the values one by one from the file and storing in a variable some. I am completely new to scripting so can you point if there is some other way to do it? Thank you in advance.

First of all stay away from dangerous back-ticks - for i in `cat ./eff_cal.txt` and use a while loop instead:

Assuming you have numbers in file: eff_cal.txt Try:

while read num
do
        output=$( echo "scale=4; $num * 100 / 128" | bc -l )
        echo "$num ----- $output"
done < eff_cal.txt > some.txt
1 Like

basename is not what you think. Please refer this link

1 Like