LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   (standard_in) 1: parse error setting variable with bc (https://www.linuxquestions.org/questions/linux-newbie-8/standard_in-1-parse-error-setting-variable-with-bc-892587/)

fjcc90 07-19-2011 04:13 PM

(standard_in) 1: parse error setting variable with bc
 
I'm trying to define a variable, CHAN, by dividing another variable, FREQ, by a number. FREQ is a value from a file (called header.txt). What I think I'm doing with this bit of code is reading a number from header.txt whose location is specified by the head and tails, assigning it to FREQ and then defining CHAN with bc.

Code:

#!/bin/bash
while read FREQ
        do tail -n +7 | tail -c +11 | head -c 8
done<header.txt
CHAN=`echo "$FREQ / 1.28"|bc`

However, when I run this I get the error: (standard_in) 1: parse error. I suspect the problem is with how I am reading the value of FREQ because if I run this:
Code:

FREQ=4
CHAN=`echo "$FREQ / 1.28"|bc`

it returns 3, which is right (sort of).

Any ideas on how to fix this?
Thanks

chrism01 07-19-2011 05:54 PM

If you use
Code:

set -xv
as the 2nd line of your script ie immediately after #!/bin/bash, it'll show you exactly what's happening in detail. Great for debugging.
:)

grail 07-20-2011 02:59 AM

Chris' advice is sound. I would also ask what you think the while loop is doing?
I would suggest looking back at whatever source you use for bash information to see how this construct works.


All times are GMT -5. The time now is 09:43 AM.