"Command not found" error using expr in shell script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
i have to results in
$sum=expr $logicsubs+ $renew
$sum=`expr $subscription + $renew`
i want to sum these variables but error comes
expr: non-numeric argument
./revenue.sh: line 18: =: command not found
2. Do not use backticks ("`" symbol) while defining a variable. Instead of this, use following pattern:
It is not wrong to use backquotes rather than $( ) to generate the output of a command as a string to assign to a variable (or for any other purpose); it is a matter of personal preference. Details here.
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
It may not be wrong to use `..` backticks, but it's not recommended, and generally deprecated. $(..) is much better all around. It's also posix-specified, so it's portable to all but the oldest shells. Read the link catkin provided.
Similarly, all posix-compliant shells have integer arithmetic built in to them, so expr is pretty much completely unnecessary too. The $((..)) expansion form is fully portable, and similar to the command substitution brackets.
On the other hand, as mentioned, very few shells have floating point math built-in, and expr doesn't support it either. You have to use an external command such as bc or awk for that.
Finally, if the data is in integer form, you might check to make sure your mysql commands aren't producing dos-based newlines. The invisible carriage returns can confuse many commands.