Visit Our UNIX and Linux User Community


bc giving error: (standard_in) 2: parse error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bc giving error: (standard_in) 2: parse error
# 1  
Old 08-04-2010
bc giving error: (standard_in) 2: parse error

Below part of script, is working fine sometimes and gives error sometime.
I am doing float operations, checking if x > y.

##########CODE##########
Code:
THRESHOLD="1.25"
ratio=$( echo "scale=2; ${prev}/${current}" | bc )
 
if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; then 
    split_date=`echo ${line} | cut -d, -f2`
fi

########################

below is the error i am getting -

Code:
script/split_checks.sh: line 62: [: -eq: unary operator expected
(standard_in) 2: parse error
(standard_in) 1: parse error

Thanks,
Manish

---------- Post updated at 10:47 AM ---------- Previous update was at 10:41 AM ----------

i have put checks to make sure that prev & current are non-zero values....

Last edited by pludi; 08-04-2010 at 03:56 AM..
# 2  
Old 08-04-2010
change
Code:
if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; the

to

Code:
if [ ${ratio} > ${THRESHOLD} ]; then

# 3  
Old 08-04-2010
Instead of

Code:
if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; then

try

Code:
if [ $ratio -le $THRESHOLD ]; then

The reason your shell is complaining is because '$(echo "${ratio} > ${THRESHOLD}" | bc' is throwing an error.
# 4  
Old 08-04-2010
pravin and agn - looks like what you guys said is not helping

#################### CODE ####################
Code:
#!/bin/sh

a="1.23"
b="2.45"

if [ $a > $b ]; then 
    echo "string compare: greater : $a > $b"
else
    echo "string compare: smaller : $a < $b"    
fi

if [ $a -ge $b ]; then 
    echo "int compare: greater : $a > $b"
else
    echo "int compare: smaller : $a < $b"   
fi

if [ $( echo "$a > $b" | bc ) -eq 1 ]; then 
    echo "using bc: greater : $a > $b"
else
    echo "using bc: smaller : $a < $b"
fi

exit 0

#########################################

and output is

Code:
$ ./test.sh
string compare: greater : 1.23 > 2.45
./test.sh: line 12: [: 1.23: integer expression expected
int compare: smaller : 1.23 < 2.45
using bc: smaller : 1.23 < 2.45

the first greater is wrong and second (-le/-ge) is giving error

---------- Post updated at 11:05 AM ---------- Previous update was at 11:05 AM ----------

i want to know the reason for this error:
Code:
(standard_in) 2: parse error
(standard_in) 1: parse error

shell error will go if "bc" works fine.

Last edited by pludi; 08-04-2010 at 03:57 AM..
# 5  
Old 08-04-2010
Ah, floating point. Plain shell operators can't handle floating point math. Use perl or awk.
# 6  
Old 08-04-2010
whats wrong with this line:
Code:
if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; then

why is it giving error:
Code:
(standard_in) 2: parse error
(standard_in) 1: parse error



---------- Post updated at 11:43 AM ---------- Previous update was at 11:42 AM ----------

it should give error only in case one of the values is blank... but i have added enough checks to make sure that they should have atleast 0 value

Last edited by pludi; 08-04-2010 at 03:57 AM..
# 7  
Old 08-04-2010
bc is probably throwing an error. On my system

Code:
$ echo '1 > 2' | bc
syntax error on line 1, teletype


Previous Thread | Next Thread
Test Your Knowledge in Computers #240
Difficulty: Easy
In 1973, a transatlantic satellite link connected the Norwegian Seismic Array (NORSAR) to the ARPANET, making Norway the first country outside the US to be connected to the network.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

(standard_in)1:syntax error using bc with Cron

I created a shell script to record server temperature. When I manually run script it works fine with no error message. But when I create a cron job, my script fails with error message (standard_in)1:syntax error. I figured out the bc utility is causing the error message. Below is my script. ... (7 Replies)
Discussion started by: SysAdminRialto
7 Replies

2. Shell Programming and Scripting

Standard_in error

# echo '6.5 < 2.7 ' |bc 0 # echo '4.8.5 > 4.8.4' |bc (standard_in) 1: syntax error (standard_in) 1: syntax error ---------------------------------------------------------- FILESET_A_VER_CHK2=4.8.5 FILESET_R_NAME_CHK2=4.8.5 if ] ; then ## echo "Fileset is higher " ... (2 Replies)
Discussion started by: Mathew_paul
2 Replies

3. Shell Programming and Scripting

If condition giving syntax error. Need help.

Hi, I have an if condition on executing it is giving syntax error as below: -------------------------------------------------------------------------------------- line 61: syntax error in conditional expression ./play_test.sh: line 61: syntax error near `]' ./play_test.sh: line 61: ` if... (2 Replies)
Discussion started by: ramki067
2 Replies

4. Shell Programming and Scripting

(standard_in) 1: parse error

Hi, I am trying to make a script that tries to compare two values and print if one is greater than another. It seems to return a (standard_in) 1: parse error at times. #!/bin/sh a= awk '{print $1}' file1.txt b= awk '{print $1}' file2.txt c= awk '{print $1}' file3.txt x= awk '{print... (5 Replies)
Discussion started by: jamie_123
5 Replies

5. AIX

multipath giving error

Hi, # lspath Missing hdisk0 fscsi0 Missing hdisk1 fscsi0 Missing hdisk2 fscsi0 Missing hdisk3 fscsi0 Missing hdisk4 fscsi0 Missing hdisk5 fscsi0 Missing hdisk6 fscsi0 Missing hdisk7 fscsi0 Missing hdisk8 fscsi0 Missing hdisk9 fscsi0 Missing hdisk10 fscsi0 Missing hdisk11... (2 Replies)
Discussion started by: JATA01
2 Replies

6. Shell Programming and Scripting

(standard_in) 1: parse error

Hi all, Could someone please to tell me when do we exactly get the below error and how to get rid of it. I am unable to trace the error. (standard_in) 1: parse error Thanks in advance !! (4 Replies)
Discussion started by: sparks
4 Replies

7. BSD

Xarchiver giving error messages

I have FreeBSD installed with Xarchiver and when extracting files through the file manager ("Extract here..." option) the following error pops up: tar: unrecognized option `--overwrite' Perhaps this is a known error and is there a way to solve it? (10 Replies)
Discussion started by: figaro
10 Replies

8. UNIX and Linux Applications

apt-get install giving error

Hello when i am giving a command apt-get install I am getting error as below: " apt-get: error while loading shared libraries: libapt-pkg-libc6.3-6.so.3.11: cannot open shared object file: No such file or directory " can u suggest what to do. https://www.unix.com/images/misc/progress.gif... (1 Reply)
Discussion started by: pradeepreddy
1 Replies

9. Linux

acroread command giving error

Hi, When I run the command acroread it is giving error ERROR: Cannot find installation directory. When I look at /usr/local/Adobe/Acrobat7.0/bin/ an exicutable file named acroread is there. When i run ./acroread from that directory it is working . What can i do so that I can give... (3 Replies)
Discussion started by: iamjayanth
3 Replies

10. UNIX for Advanced & Expert Users

script giving error

Hi All, i have an small issue... echo " " eval x=$@ export x=`echo $x` echo $x ssh user@ipadrss; cd /mbbv/home/; cd /mbbv/home/orange/orange/ echo pwd bash samplescript.sh $x above is my script which will triger from server A and will connect to server B for some... (2 Replies)
Discussion started by: Shahul
2 Replies

Featured Tech Videos