Expression1{ (.*/)"` the hyphen is dropped as long as there is a hyphen in front of the $FLAG shell variable. The colon operator gives a portion of the FLAG variable, which is matched by a subexpression in the middle of the/(and/) character (backslash, open parenthesis and backslash, closing parenthesis). The colon operator gives the number of characters to match if you omit the/(and/) subexpression characters. If the $FLAG variable is set to-(hyphen), the command displays a syntax error message. This is because the shell replaces the value of the $FLAG variable before running the expr command. The expr command does not know that a hyphen is a value of a variable. It can only understand: - : -*/(.*/)
And it interprets the first hyphen as a minus operator. To eliminate this problem, use: flag= ' expr ' x$flag ': x-*/(. * *) "'
You want to useExprCommand inifStatement, enter:If expr "$ANSWER": "[YY]" >/dev/null
then return ANSWER to start with "Y" or "Y" fi
If the $ANSWER variable starts with Y or y, the then portion of theif statement executes. If the result of a matching success expression is 1, and the expr command returns an export value of 0, the export value is recognized by the if statement as logical value True. If the match fails, the result is 0, and the export value is 1. Redirects the standard output of the expr command to the /dev/null special file, discarding the result of the expression. If you do not redirect it, the result is written to standard output, usually your workstation monitor. Consider the following expression: Expr "$STR" = "="
If the $STR variable has a value of = (equal sign), theexpr command sees the expression after the shell finishes processing the command: = = =
The expr command interprets this as the three equals operator in a row and displays a syntax error message. This can happen once the value of the shell variable is the same as one in the expr operator. The way to avoid this problem is to write the expression: Expr "x$str" = "x="
To return the length of the $SHELL environment variable/usr/bin/ksh, enter:Expr length $SHELL
Display the following: 12
To return to the first position in "abcdef" where any one of the characters in the "de" string appears, enter:Expr Index abcdef de
Display the following: 4
To return any character of the "FD" string to the first occurrence in "abcdef", enter:Expr Index abcdef FD
Display the following: 4
To return a string of 6 characters in the "Goodnight Ladies" string starting at position 11, enter:Expr substr "Goodnight Ladies" 11 6
Display the following: Ladies
|