Bash Expr Multiply Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this expr syntax error multiplication site About Us Learn more about Stack Overflow the company Business Learn more expr syntax error in shell script about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x bash expr math Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Multiplication with
Multiplication In Unix Shell Script
expr in shell script up vote 2 down vote favorite 1 I am making a basic calculator to add, subtract, multiply, and divide. Addition works, but not multiplication. When I attempt to multiply, I get the "You did not run the program correctly" response: $ ./calculator 4 + 5 9 $ ./calculator 4 * 5 You did not run the program correctly Example: calculator 4 bash multiplication decimals + 5 I've searched around on google, where I found the \\* code, but still doesn't work. Can someone provide me with a solution or explanation? Here is my code #!/bin/bash if [ $# != 3 ]; then echo You did not run the program correctly echo Example: calculator 4 + 5 exit 1 fi if [ $2 = "+" ]; then ANSWER=`expr $1 + $3` echo $ANSWER fi if [ $2 = "*" ]; then ANSWER=`expr $1 \\* $3` echo $ANSWER fi exit 0 linux bash shell unix expr share|improve this question edited Nov 30 '14 at 21:07 that other guy 45k54070 asked Nov 30 '14 at 20:55 Alex Wolfe 11112 It's unlikely you need expr; ANSWER=$(( $1 + $3 )), for example, should work with any shell you are likely to be using with Linux. –chepner Nov 30 '14 at 21:36 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote Your code has many problems. Here is a fix. * means "all files in the current directory". To instead mean a literal asterisk/multiplication character, you have to escape it: ./calculator 3 \*
functionality list is quite similar to that of UNIX and become very popular over the last several years. bash multiplication variable Our Basic motive is to provide latest information about Linux Operating system.
Shell Script For Multiplication Of Two Numbers
Python Programming Python is a comparatively simple programming language, compared to c++. Although some of the benefits
Shell Script Multiplication Table
of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many "intuitive" features. For this reason it is common and recommended http://stackoverflow.com/questions/27218141/multiplication-with-expr-in-shell-script by most professionals that people new to programming start with python. Perl Programming Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. http://www.bashguru.com/2010/12/math-in-shell-scripts.html They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files. Android Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly. Sunday, December 26, 2010 Posted by venu k 144 comments | 7:36 AM Math in Shell Scripts One thing that often confuses new users to the Unix / Linux shell, ishow to do (even very simple) maths. In most languages, x = x + 1 (oreven x++) does exactly what you would expect. The Unix/Linux shell isdifferent,however. It doesn't have any
Today's Posts Advanced Search Find the answer to your Linux question: Entire Site Articles Downloads Forums Linux Hosting Forum Your Distro Red Hat / Fedora Linux "expr" http://www.linuxforums.org/forum/red-hat-fedora-linux/138692-expr-command-wont-multiply.html command won't multiply If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be shell script displayed. ** Linuxforums now supports the Tapatalk app for your mobile device. Results 1 to 4 of 4 Thread: "expr" command won't multiply Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Enjoy an ad free experience by logging in. Not a member yet? Register. 01-16-2009 #1 glamiss View Profile View expr syntax error Forum Posts Private Message View Articles Just Joined! Join Date Jan 2009 Location Minneapolis, MN Posts 15 "expr" command won't multiply so i'm trying to use expr to get the PRODUCT of two numbers... my kernel is rhes4: $ uname -a Linux