Operating System - HP-UX
1832759 Members
2974 Online
110045 Solutions
New Discussion

Re: 'bc' utility in HP-UX cannot understand conditionals?

 
SOLVED
Go to solution
Daniel Gowans
Advisor

'bc' utility in HP-UX cannot understand conditionals?

I have a cshell script that does the following:

set result = `echo "( $Val1 - $Val2 ) > 5.65 | bc`

According to everyone I talk to, this should work fine, but I get a syntax error. Even the man page (man bc) says that it should work.

However, if I use a program called 'bs' in place of 'bc' then everything works fine. The only problem is that 'bs' doesn't exist on any of our other systems, and most people never seem to have heard of it.

1. Why isn't 'bc' doing what the man page says it will?

2. What is 'bs' and why has nobody heard of it?

Thanks!
Daniel Gowans
Compeq International
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: 'bc' utility in HP-UX cannot understand conditionals?

Mainly because bs and bc have nothing to do with each other. Bs is a seldom used BASIC interpreter - and a very "lite" one at that. Bc is a calculator but can be found on almost any UNIX box.

This is probably as close an equivalent:

echo "x = 0; if ((${val1} - ${Val2}) > 5.65) x = 1; x" | bc

This will echo 1 if true 0 if false.

You can add the ` `'s.

If it ain't broke, I can fix that.
Paula J Frazer-Campbell
Honored Contributor

Re: 'bc' utility in HP-UX cannot understand conditionals?

Hi

Has someone renamed BC to BS ??


Just an Idea.

Paula
If you can spell SysAdmin then you is one - anon
Darren Prior
Honored Contributor

Re: 'bc' utility in HP-UX cannot understand conditionals?

Hi Daniel,

I see the same result as you. I think you may need to do more "setup" in bc before you can run your statement through it, but it's been a while since I've used it.

bs is a simple programming language - more info on this can be found in its man page.

regards,

Darren.
Calm down. It's only ones and zeros...
Jdamian
Respected Contributor

Re: 'bc' utility in HP-UX cannot understand conditionals?

I don't agree with you when you wrote 'Even the man page (man bc) says that it should work'.

Accoding to my bc man pages, the following example is not valid as an expression:

3.0 > 9.2

According to manual pages:

Statements
E
{ S ; ... ; S }
if ( R ) S
while ( R ) S
for ( E ; R ; E ) S
null statement
break
quit

where 'E0' means EXPRESSION. But symbols >, <, >= ... don't constitute an EXPRESSION. They can be used only whithin an R ( relational operation)... and as you can see above 'R' only appears in 'if', 'while' and 'for' statements, not just alone as E.
Daniel Gowans
Advisor

Re: 'bc' utility in HP-UX cannot understand conditionals?


I understand now. It was mostly confusing me because of the man page. The previous sections saying E op E yields R made me think I could evaluate it on a single line. Go figure. Luckily there are better tools out there. I just wish it had kept up with GNU 'bc'

Daniel