Thanks to everybody for your help and explainations. I ended up with what I needed and an explaination of how somethings work. I also have a direction on where to learn more
thanks again david On Wed, 11 Dec 2002, Robert P. J. Day wrote: > On Wed, 11 Dec 2002, dbrett wrote: > > > Now I am really confused! > > > > This works: > > #!/bin/bash > > > > if [ -z $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 > > assuming that all you're doing is asking a shell script to run > "bc" for you, here's a possible solution: > > ------------- > > #!/bin/bash > > function usage { > cat <<-EOF > Usage: $0 equation. > Aborting now. > exit > EOF > } > > [[ $# -eq 1 ]] || usage > > echo $1 | /usr/bin/bc -l 2> /dev/null > > ------------- > > notes: > > 1) the usage() function keeps that stuff out of the way, so you can call > it more than once > > 2) [[ $# -eq 1 ]] is the recognized way to test the number of > parameters > > > and if all you're doing is simple arithmetic, this is already > built into bash with the $(( )) construct, as in: > > $ echo $(((2+3)*10)) > 50 > > using this built-in construct, you need not worry about whitespace > since the construct is an inherent part of the shell. > > rday > > > > -- > redhat-list mailing list > unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe > https://listman.redhat.com/mailman/listinfo/redhat-list > -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list