Home About BC DR HA Support Training Download
You are here: Home/ Training/ Unix-Bourne-Shell/ Please Login or Register

-
Current Location
-

js
  Training
    Unix-Bourne-Shell
-
AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com


Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com

-
digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

-

Manual: expr(1)

-

Please contact or Mt Xia for assistance with all your shell programming needs.


expr(1)								      expr(1)



NAME
  expr - Evaluates arguments as	expressions

SYNOPSIS

  expr expression

DESCRIPTION

  The expr command reads an expression,	evaluates it, and writes the result
  to standard output.  Within the expression argument, you must	separate each
  term with spaces, precede characters special to the shell with a \
  (backslash), and quote strings containing spaces or other special charac-
  ters.	 Note that expr	returns	0 to indicate a	zero value, rather than	the
  null string.	Integers can be	preceded by a unary minus sign.	 Internally,
  integers are treated as 64-bit or 32-bit two's complement numbers, depend-
  ing on the word size of the hardware platform.

  The operators	and keywords are described in the following listing.  Charac-
  ters that need to be escaped are preceded by a \ (backslash).	 The list is
  in order of increasing precedence with equal precedence operators grouped
  within {} (braces).

  expression1 \| expression2
      Returns expression1 if it	is neither null	nor 0 (zero); otherwise,
      returns expression2.

  expression1 \& expression2
      Returns expression1 if neither expression1 nor expression2 is null nor
      0; otherwise, returns 0.

  expression1 {	 =,  \>,  \>=,	 \<,  \<=,  !=	} expression2
      Returns the result of an integer comparison if both expressions are
      integers;	otherwise, returns the result of a string comparison.

  expression1 :	expression2 or match expression1 expression2
      Compares expression1 with	expression2, which must	be a regular expres-
      sion, with syntax	as described for grep, except that all patterns	are
      anchored,	so ^ (circumflex) (which anchors a pattern to the beginning
      of a line) is not	a special character in this context.

      Normally,	the matching operator returns the number of characters
      matched.	Alternatively, you can use the \(...\) symbols in expression2
      to return	a portion of expression1.

  grep
  command.

  FUNCTIONS

  The expr command provides the	following string-expression functions.
  Strings containing white space must be quoted.  The first character of a
  string is position 1.	 The information returned by all of these functions
  is in	the form of a string:

  index	string1	string2
      Compares each character in the second string against each	character in
      the first	string and returns the position	in the first string of the
      first match found, where the first match is the match closest to the
      beginning	of string1.

  length string
      Returns the length of the	string argument.

  match	string1	string2
      See the description of the : (colon) match operator, above.

  substr string	start length
      Returns the substring of string that begins at character position	start
      and is length characters long.

EXAMPLES

   1.  To increment a shell variable, enter:
	    COUNT=`expr	$COUNT + 1`


       This adds 1 to the COUNT	shell variable (see sh for details).

   2.  To find the length of a shell variable, enter:
	    RES=`expr "$VAR" : ".*"`


       Note that VAR is	in double quotes to avoid problems where VAR is	NULL
       or contains embedded spaces.  The regular expression is also quoted to
       avoid expansion by the shell.  This operation can also be performed
       as:
	    RES=`expr length "$VAR"`


   3.  To use part of a	shell variable,	enter:
	    RES=`expr "$VAR" : "-*\(.*\)"`


       This removes leading - (dashes),	if any,	from VAR.  If the \( \)	char-
       acters were omitted, RES	would contain the length of VAR.

   4.  To find a character from	one string in another string, enter:
	    INDEX=`expr	index "Hello World!" "Wo"`


       Note that the returned value is 5, not 7.  The first match is the
       fifth character in string1, matching the	o in string2 rather than the
       W, which	is the seventh character in string1.

   5.  Special considerations:
	    RES=`expr "x$VAR" :	"x-*\(.*\)"`


       This succeeds even if VAR has the value - (dash).
	    RES=`expr "x$VAR" =	"x="


       This succeeds even if VAR has the value = (equal	sign).

EXIT VALUES

  The expr command returns the following exit values:

  0   The expression is	neither	null nor 0.

  1   The expression is	null or	0.

  2   The expression is	invalid.

RELATED	INFORMATION

  Commands:  grep(1)/egrep(1)/fgrep(1),	sh(1), test(1).

  Functions: string(3),	wcscat(3) wcsmp(3) wcscpy(3)

-
Manual: expr(1)
-
 

Introduction
Table of Contents
Chapter 1
Chapter 2a
Chapter 2b
Chapter 3
Chapter 4a
Chapter 4b
Chapter 5a
Chapter 5b
Chapter 6a
Chapter 6b
Chapter 6c
Chapter 7a
Chapter 7b
Chapter 8
Chapter 9a
Chapter 9b
Manual: ar(1)
Manual: cb(1)
Manual: cc(1)
Manual: expr(1)
Manual: f77(1)
Manual: ftp(1)
Manual: ksh(1)
Manual: lint(1)
Manual: sh(1)
Manual: test(1)
Manual: time(1)


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com