Sponsored Content
Top Forums UNIX for Dummies Questions & Answers A perfect number shell program Post 302360219 by decent on Thursday 8th of October 2009 10:34:37 AM
Old 10-08-2009
I see there has already been a reply but for the sake of education fire up a shell and do some testing.

Code:
$ echo `expr 4 / 2`
2
$ echo 'expr 4 / 2'
expr 5 / 2
$ echo $(expr 4 / 2)
2

As you can see here both the backticks `command`and $(command) give the desired result while 'command' just gives you text string "command" back.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Write a shell program to find the sum of alternate digits in a given 5-digit number

Hi Can any one please post the answer for the above program.................. (4 Replies)
Discussion started by: banta
4 Replies

2. Shell Programming and Scripting

Prime Number Program (Fun)

Hi, I was just wondering if anyone has, or knows where to download a prime number finder program. I would like a fairly simple bash program, and also I would like one that could take advantage of multiple processors. I have 500 cores I can use, and would like to take advantage of them using a... (2 Replies)
Discussion started by: Kweekwom
2 Replies

3. Shell Programming and Scripting

extraction of perfect text from file.

Hi All, I have a file of the following format. <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user... (5 Replies)
Discussion started by: nua7
5 Replies

4. UNIX for Dummies Questions & Answers

Script producing error, Program to calculate maximum number

Hi folks, Here i have written a shell script to calculate a maximum number from 10 numbers entered on command line. max=0 echo Enter 10 numbers , one at a time for i in 1 2 3 4 5 6 7 8 9 10 do read n max=`expr $max + $n` if --- At this last step there is some problem, it gives error... (5 Replies)
Discussion started by: rits
5 Replies

5. AIX

I want the perfect user-interface

I've got an aix-box somewhere on the network and a PC on my desk. Nothing fancy so far. The PC is made dual-boot: - windowsXP with putty & winSCP or - slackware 13 with xfce4 installed. The aix-box runs DB2 v8.2 and I've installed db2top to monitor the database. db2top is a character... (0 Replies)
Discussion started by: dr_te_z
0 Replies

6. Shell Programming and Scripting

ksh program that finds the lowest number in a .txt file

i am having a problem finding the lowest number after punching in a bunch of numbers in the .txt file but its probably the way i have the code set up. help please! (4 Replies)
Discussion started by: tinsteer
4 Replies

7. Solaris

Resolving port number to program name

I was just checking to see if anyone had a script that would allow me to go from port number to program name. I tried to create my own script but it looks like it only works for IPv4 sockets and it looks like daemons such as sshd return as AF_INET6 (in pfiles) for some reason. I can fix my script... (0 Replies)
Discussion started by: thmnetwork
0 Replies

8. UNIX for Dummies Questions & Answers

Can you perfect my sed ?

I want to print only the lines that meet the criteria : "worde:" and "wordo;" I got this far: sed -n '/\(*\)\1e:\1o;/p;' But it doesn't quite work. Can someone please perfect it and tell me exactly how its a fixed version/what was wrong with mine? Thanks heaps, (1 Reply)
Discussion started by: maximus73
1 Replies

9. Shell Programming and Scripting

count number of entries perl program or Unix script

Hi I have a file with number of entries name 1 123 name 1 345 name 1 65346 name2 3243 name2 24234 name 2 234234 so on ......... how to count total number of entries for name 1 and name2...and so on Please guide. (1 Reply)
Discussion started by: manigrover
1 Replies

10. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies
expr(1) 						      General Commands Manual							   expr(1)

NAME
expr - evaluate arguments as an expression SYNOPSIS
arguments DESCRIPTION
takes arguments as an expression, evaluates, then writes the result on the standard output. Terms in the expression must be separated by blanks. Characters special to the shell must be escaped. Note that rather than the null string, is returned to indicate a zero value. Strings containing blanks or other special characters should be quoted. Integer-valued arguments can be preceded by a unary minus sign. Internally, integers are treated as 32-bit, 2's complement numbers. The operators and keywords are listed below. Characters that need to be escaped are preceded by The list is in order of increasing prece- dence with equal-precedence operators grouped within symbols. Returns the first expr if it is neither null nor otherwise returns the second expr. In the UNIX 2003 environment, returns 0 if the first expr is null or and the second expr is null. Returns the first expr if neither expr is null or otherwise returns If both arguments are integers, and if the comparison is satisfied, expr returns otherwise it returns expr returns the result of an integer comparison if both arguments are integers; other- wise returns the result of a lexical comparison (note that and are identical, in that both test for equality). Addition or subtraction of decimal integer-valued arguments. Multiplication, division or remainder of decimal integer-valued arguments producing an integer result. The matching operator compares the first argument with the second argument which must be a regular expression. expr supports the Basic Regular Expression syntax (see regexp(5)), except that all patterns are ``anchored'' (i.e., begin with and, therefore, is not a special character, in that context. Normally, the matching operator returns the number of characters matched (0 on fail- ure). Alternatively, the pattern symbols can be used to return a portion of the first argument. The length of expr. Takes the substring of the first expr, starting at the character specified by the second expr for the length given by the third expr. Returns the position in the first expr which contains a character found in the second expr. Match is a prefix operator equivalent to the infix operator Grouping symbols. Any expression can be placed within parentheses. Parentheses can be nested to a depth of as specified in the header file EXTERNAL INFLUENCES
Environment Variables determines the collating sequence used in evaluating regular expressions and the behavior of the relational operators when comparing string values. determines the interpretation of text as single- and/or multi-byte characters, and the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C" (see environ(5)). If is set to it enables the UNIX 2003 Standard environment. International Code Set Support Single- and multi-byte character code sets are supported. RETURN VALUE
As a side effect of expression evaluation, expr returns the following exit values: Expression is neither null nor zero. Expression is null or zero. Invalid expression. An error occurred while evaluating the expression. DIAGNOSTICS
Operator or operand errors Arithmetic attempted on a string EXAMPLES
Add 1 to the shell variable For equal to either or just return the last segment of a path name (i.e., Beware of alone as an argument because expr interprets it as the division operator (see below): A better representation of the previous example. The addition of the characters eliminates any ambiguity about the division operator and simplifies the whole expression: Return the number of characters in WARNINGS
After argument processing by the shell, expr cannot tell the difference between an operator and an operand except by the value. If is an the command: resembles: as the arguments are passed to expr (and they will all be taken as the operator). The following works: AUTHOR
was developed by OSF and HP. SEE ALSO
sh(1), test(1), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
expr(1)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy