On Wed, 2002-12-11 at 12:05, dbrett wrote: > I have a bash to math calucations. It works but also complains about the > last line, even though it works. > > Any ideas how to fix the problem or at least not see the error message and > still work. > > #!/bin/bash > > if [$1 == '']; then > echo '' > echo "format is $0 'math equation'" > echo "i.e. $0 (2+2)*3" > echo '' > exit > fi > > echo $1 | /usr/bin/bc -l &2>/dev/null >
only way I can get it to work is to quote the equation and fix the syntax of the test statement. #!/bin/bash if [ -z $1 ]; then # spaces inside the [ ] -z test for null string echo '' echo "format is $0 'math equation'" echo "i.e. $0 (2+2)*3" echo '' exit fi echo $1 | /usr/bin/bc -l 2>/dev/null Roberts suggestion of dropping the &2> in favor of 2> fixed a really funky newline thing I will have to figure out some day :) [bhughes@bretsony bhughes]$ bc.test.sh format is ./bc.test.sh 'math equation' i.e. ./bc.test.sh (2+2)*3 [bhughes@bretsony bhughes]$ bc.test.sh (2+2)*3 bash: syntax error near unexpected token `(2+2)' [bhughes@bretsony bhughes]$ [bhughes@bretsony bhughes]$ bc.test.sh '(2+2)*3' 12 HTH Bret -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list