On Thu, 12 May 2005, Tony Jo wrote:
Hello, I am having issues with a bash script and I was wondering if anyone
could be of assistance? Its just that our lecturer assumed it would be easy
to pick up and do an assignment on, even though we haven't learnt it and its
not a pre-requisite.
But anyway, I noticed when I use the cut command to obtain some numbers from
a file, I cannot use it in an arithmetic operation. I tried the following:
temp='expr $val1 + $val2'
But I get the following error message:
expr: non-numeric argument
When quoting parts of a script or error messages, please be
accurate (cut and paste rather than retyping). You used:
temp=`expr $val1 + $val2`
or you wouldn't have received that error. The line you have would
have assigned the literal value to $temp.
I was wondering if BASH requires type conversion? I even printed out the
values for $val1 and $val2. They look like integers to me. If anyone could
help me, it would be greatly appreciated.
What are the values of $val1 and $val2? Use this command to see
them:
printf ":%s:%s:\n" "$val1" "$val2"
What is the result of:
echo $(( $val1 + $val2 ))
What command did you use to fill those variables?
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
==================================================================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/ssr.html>
_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash