1 .\" You may copy, distribute and modify under the terms of the LDP General
2 .\" Public License as specified in the LICENSE file that comes with the
3 .\" gnumaniak distribution
5 .\" The author kindly requests that no comments regarding the "better"
6 .\" suitability or up-to-date notices of any info documentation alternative
7 .\" is added without contacting him first.
9 .\" (C) 1999-2002 Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
12 .\" man pages are NOT obsolete!
13 .\" <ragnar@ragnar-hojland.com>
15 .\" Japanese Version Copyright (c) 2000 NAKANO Takeo all rights reserved.
16 .\" Translated Sun 12 Mar 2000 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
17 .\" Updated & Modified Sat Jan 24 13:37:04 JST 2004
18 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
20 .\"WORD: token ¥È¡¼¥¯¥ó
21 .\"WORD: operand ¥ª¥Ú¥é¥ó¥É
22 .\"WORD: null (character) ¥Ê¥ë(ʸ»ú)
23 .\"WORD: operator ±é»»»Ò
24 .\"WORD: subexpression Éûɽ¸½
26 .TH expr 1 "18 June 2002" "GNU Shell Utilities 2.1"
28 .\"O expr \- evaluate expressions
33 .BI "expr " expression...
35 .B expr [\-\-help] [\-\-version]
40 .\"O evaluates an expression and writes the result on its standard output.
41 .\"O Each token of the expression must be a separate argument.
43 ¤Ï¼°¤òɾ²Á¤·¡¢¤½¤Î·ë²Ì¤òɸ½à½ÐÎϤ˽ñ¤½Ð¤¹¡£
44 ¼°¤Î¥È¡¼¥¯¥ó (token) ¤Ï¤½¤ì¤¾¤ìÊÌ¡¹¤Î°ú¿ô¤ÇÍ¿¤¨¤ëɬÍפ¬¤¢¤ë¡£
46 .\"O Operands are either numbers or strings. \fBexpr\fP converts anything
47 .\"O appearing in an operand position to an integer or a string depending on
48 .\"O the operation being applied to it. Strings are not quoted for
49 .\"O \fBexpr\fP itself, though you may need to quote them to protect
50 .\"O characters with special meaning to the shell (e.g, spaces)
51 ¥ª¥Ú¥é¥ó¥É (operand) ¤Ï¿ô»ú¤Þ¤¿¤Ïʸ»úÎó¤Ç¤¢¤ë¡£
53 ¤Ï¥ª¥Ú¥é¥ó¥É¤Î°ÌÃ֤˸½¤ì¤¿¤â¤Î¤ò¡¢¤½¤ì¤ËÂФ·¤Æ¹Ô¤ï¤ì¤ë±é»»¤Ë±þ¤¸¤Æ
54 À°¿ô¤Þ¤¿¤Ïʸ»úÎó¤ËÊÑ´¹¤¹¤ë¡£
57 ¤Ç¤Ï¥¯¥©¡¼¥È¤·¤Ê¤¯¤Æ¤è¤¤¤¬¡¢
58 ¥·¥§¥ë¤«¤éÊݸ¤ë¤¿¤á¤Î°úÍÑÉ䤬ɬÍפ«¤â¤·¤ì¤Ê¤¤ (¥¹¥Ú¡¼¥¹¤Ê¤É)¡£
60 .\"O Operators may given as infix symbols or prefix keywords. Parentheses
61 .\"O may be used for grouping in the usual manner (you must quote parentheses
62 .\"O to avoid the shell evaluating them, however).
63 ±é»»»Ò¤Ï 2 ¹à´Ö¤ËÁÞÆþ¤µ¤ì¤ë¥·¥ó¥Ü¥ë¤È¤·¤Æ¡¢
64 ¤Þ¤¿¤ÏÁ°ÃÖ¤µ¤ì¤ë¥¡¼¥ï¡¼¥É¤È¤·¤ÆÍ¿¤¨¤é¤ì¤ë¡£
65 ³ç¸Ì¤âÄ̾ï¤Î¤è¤¦¤Ë¥°¥ë¡¼¥×²½¤ËÍøÍѤǤ¤ë
66 (¤·¤«¤·¥·¥§¥ë¤Ë¤è¤ë²ò¼á¤òÈò¤±¤ë¤¿¤á¤Ë¤Ï³ç¸Ì¤ò¥¯¥©¡¼¥È¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤)¡£
69 .\"O returns the following exit status:
71 ¤Ï°Ê²¼¤Î½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤òÊÖ¤¹:
73 .\"O 0 if the expression is neither null nor 0,
74 0: ¼°¤¬¥Ê¥ë¤Ç¤â 0 ¤Ç¤â¤Ê¤¤
76 .\"O 1 if the expression is null or 0,
79 .\"O 2 for invalid expressions.
81 .\"O .SH OPERATORS (in order of increasing precedence)
86 .\"O Yields its first argument if it is neither null nor 0, otherwise its
87 .\"O second argument. This is the usual `or' operation.
88 º¸¹à¤¬¥Ê¥ë¤Ç¤â 0 ¤Ç¤â¤Ê¤±¤ì¤Ðº¸¹à¤òÊÖ¤¹¡£
89 ¥Ê¥ë¤ä 0 ¤À¤Ã¤¿¾ì¹ç¤Ï±¦¹à¤òÊÖ¤¹¡£
90 ¤³¤ì¤ÏÄ̾ï¤Î `or' ±é»»¤Ë¤¢¤¿¤ë¡£
92 .\"O Yields its first argument if neither argument is null or 0,
94 º¸¹à¡¢±¦¹à¤È¤â¥Ê¥ë¤Ç¤â 0 ¤Ç¤â¤Ê¤±¤ì¤Ðº¸¹à¤òÊÖ¤¹¡£
95 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï 0 ¤È¤Ê¤ë¡£
96 .IP "\fB<\fP\0 \fB<=\fP\0 \fB=\fP\0 \fB==\fP\0 \fB!=\fP\0 \fB>=\fP\0 \fB>\fP"
97 .\"O Compare their arguments and return 1 if the relation is true, 0
98 .\"O otherwise. (\fB==\fP is a synonym for \fB=\fP.)
99 .\"O \fBexpr\fP tries to convert both arguments to numbers and
100 .\"O do a numeric comparison; if it fails when trying to convert either
101 .\"O argument it then does a lexicographic comparison.
102 ξ¹à¤òÈæ³Ó¤·¡¢´Ø·¸¤¬¿¿¤Ê¤é 1¡¢µ¶¤Ê¤é 0 ¤òÊÖ¤¹
103 (\fI==\fP ¤Ï \fI=\fP¤ÈƱµÁ¡Ë¡£
104 \fBexpr\fP ¤Ï¤Þ¤ºÎ¾Êý¤Î¹à¤ò¿ôÃͤËÊÑ´¹¤·¡¢
105 ¿ôÃÍŪ¤ÊÈæ³Ó¤ò¹Ô¤ª¤¦¤È¤¹¤ë¡£
106 ¤É¤Á¤é¤«¤Î°ú¿ô¤¬¿ôÃͤËÊÑ´¹¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¼½ñŪ¤ÊÈæ³Ó¤ò¹Ô¤¦¡£
107 .\"O .SS Numeric expressions
109 .IP "\fB+\fP\0 \fB-\fP"
110 .\"O Arithmetic addition and substraction. Both arguments are converted to numbers;
111 .\"O an error occurs if this cannot be done.
112 Âå¿ôŪ¤Ê²Ã¸º»»¤ò¹Ô¤¦¡£
113 º¸±¦¤Î¹à¤Ï¿ôÃͤËÊÑ´¹¤µ¤ì¡¢¼ºÇÔ¤·¤¿¾ì¹ç¤Ï¥¨¥é¡¼¤È¤Ê¤ë¡£
114 .IP "\fB*\fP\0 \fB/\fP\0 \fB%\fP"
115 .\"O Arithmetic multiplication, division and remainder (`%' is the remainder
116 .\"O operation, as in C). Both arguments are converted to numbers; an error
117 .\"O occurs if this cannot be done.
118 Âå¿ôŪ¤Ê¾è»»¡¦½ü»»¡¦¾ê;±é»»¤ò¹Ô¤¦
119 (`%' ¤Ï C ¤Î¾ì¹ç¤ÈƱ¤¸¤¯¾ê;±é»»¤ËÂбþ¤¹¤ë)¡£
120 º¸±¦¤Î¹à¤Ï¿ôÃͤËÊÑ´¹¤µ¤ì¡¢¤³¤ì¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ï¥¨¥é¡¼¤È¤Ê¤ë¡£
121 .\"O .SS String expressions
123 .IP "\fIstring\fP \fB:\fP \fIregex\fP"
124 .\"O Perform pattern matching. The arguments are converted to strings and the
125 .\"O second one is considered to be a (basic, a la \fBgrep\fP(1) regular
126 .\"O expression, with a `^'implicitly added at the beginning. The first
127 .\"O argument is then matched against this regular expression.
128 ¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤ò¼Â¹Ô¤¹¤ë¡£
129 º¸±¦¤Î¹à¤Ïʸ»úÎó¤ËÊÑ´¹¤µ¤ì¡¢
130 ±¦¹à¤Ï (\fBgrep\fP(1) ¤Î»È¤¦´ðËÜŪ¤Ê) Àµµ¬É½¸½¤È¤·¤Æ°·¤ï¤ì¤ë¡£
131 ±¦¹à¤Ë¤Ï°ÅÌۤΤ¦¤Á¤ËÀèƬ¤Ë `^' ¤¬¼«Æ°Åª¤ËÉղ䵤졢
132 º¸¹à¤¬¤½¤ÎÀµµ¬É½¸½¤Ë¥Þ¥Ã¥Á¤¹¤ë¤«¤Î¥Æ¥¹¥È¤¬¹Ô¤ï¤ì¤ë¡£
134 .\"O If the match succeeds and .\fIregex\fP uses `\e(' and
135 .\"O `\e)', the \fB:\fP expression returns the part of \fIstring\fP that
136 .\"O matched the subexpression; otherwise returns an integer whose value is
137 .\"O the number of characters matched.
138 ¥Þ¥Ã¥Á¤¬À®¸ù¤·¤¿¾ì¹ç¡¢
139 Àµµ¬É½¸½¤Î°ìÉô¤¬ `\e(' ¤È '\e)' ¤Ç°Ï¤ï¤ì¤Æ¤¤¤ì¤Ð¡¢
140 \fB:\fP ±é»»»Ò¤Ï \fIstring\fP ¤Î¤¦¤Á¡¢
141 Éûɽ¸½ (subexpression) ¤Ë¥Þ¥Ã¥Á¤·¤¿Éôʬ¤òÊÖ¤¹¡£
142 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¥Þ¥Ã¥Á¤·¤¿Éôʬ¤Îʸ»ú¿ô¤¬ÊÖ¤µ¤ì¤ë¡£
144 .\"O If the match fails, the \fB:\fP operator returns the null string if `\e('
145 .\"O and `\e)' are used, otherwise 0.
146 ¥Þ¥Ã¥Á¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¡¢
147 `\e(' ¤È `\e)' ¤¬»È¤ï¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¥Ê¥ëʸ»úÎ󤬡¢
148 ¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï 0 ¤¬ÊÖ¤µ¤ì¤ë¡£
150 .\"O Only the first `\e(' and `\e)' pair is relevant to the return value;
151 .\"O additional pairs are meaningful only for grouping the regular expression
153 `\e(' ¤È `\e)' ¤Î¥Ú¥¢¤Î¤¦¤Á¡¢ºÇ½é¤Î¤â¤Î¤À¤±¤¬ÊÖ¤êÃͤ˱ƶÁ¤¹¤ë¡£
154 ¤½¤ì°Ê³°¤Î¥Ú¥¢¤Ï¡¢Àµµ¬É½¸½¤Î±é»»»Ò¤ò¥°¥ë¡¼¥×²½¤¹¤ë¤È¤¤¤¦°ÕÌ£¤À¤±¤ò»ý¤Ä¡£
156 .\"O Unlike other \fBexpr\fR'ss, `\+' (one or more), `\?' (zero or one), and `\|'
157 .\"O (or connective) are recognized as matching operators.
160 ¤È°Û¤Ê¤ê¡¢`+' (1 ¤Ä°Ê¾å)¡¢`?' (0 ¤Þ¤¿¤Ï 1)¡¢`|'
161 (or Àܳ) ¤â¥Þ¥Ã¥Á¥ó¥°±é»»»Ò¤È¤·¤Æǧ¼±¤µ¤ì¤ë¡£
163 .\"O In addition, the following keywords are recognized:
164 ¤µ¤é¤Ë¡¢°Ê²¼¤Î¥¡¼¥ï¡¼¥É¤âǧ¼±¤µ¤ì¤ë:
166 .BI index " string charset"
167 .\"O Return the first position in \fIstring\fP where the first character in
168 .\"O \fIcharset\fP was found. If no character in
169 .\"O \fIcharset\fP is found in \fIstring\fP, return 0.
170 \fIcharset\fP ¤Ë¤¢¤ë¤É¤ì¤«¤Îʸ»ú¤¬ \fIstring\fP ¤Ë¸«ÉÕ¤«¤ì¤Ð¡¢
171 ¤½¤ÎºÇ½é¤Ë¸«ÉÕ¤«¤Ã¤¿°ÌÃÖ¤òÊÖ¤¹¡£¤É¤Îʸ»ú¤â¸«ÉÕ¤«¤é¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤¹¡£
174 .\"O Return the length of \fIstring\fP.
175 \fIstring\fP ¤ÎŤµ¤òÊÖ¤¹¡£
177 .BI match " string regex"
178 .\"O An alternative way to do pattern matching. This is the same as
179 .\"O ``\fIstring\fP \fB:\fP \fIregex\fP''.
180 ¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤ò¹Ô¤¦Ê̤Τä¤êÊý¡£
181 ¤³¤ì¤Ï ``\fIstring\fP \fB:\fP \fIregex\fP'' ¤ÈƱ¤¸¡£
184 .\"O Interpret \fIstring\fR as a regular string, no matter if it is an operator or
185 .\"O a keyword. Disabled when the environment variable \fBPOSIXLY_CORRECT\fR is
187 \fIstring\fP ¤ò (±é»»»Ò¤Þ¤¿¤Ï¥¡¼¥ï¡¼¥É¤¬´Þ¤Þ¤ì¤Æ¤¤¤Æ¤â) Ä̾ï¤Îʸ»úÎó¤È¤ß¤Ê¤¹¡£
188 ´Ä¶ÊÑ¿ô \fBPOSIXLY_CORRECT\fR ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È̵¸ú¤Ë¤Ê¤ë¡£
190 .BI substr " string position length"
191 .\"O Return the substring of \fIstring\fP beginning at \fIposition\fP with
192 .\"O length at most \fIlength\fP. If either \fIposition\fP or \fIlength\fP
193 .\"O isn't positive or numeric, return a null string.
194 \fIstring\fP ¤ÎÉôʬʸ»úÎó¤òÊÖ¤¹¡£
195 Éôʬʸ»úÎó¤Ï \fIstring\fP ¤Î \fIposition\fP ¤«¤é»Ï¤Þ¤ê¡¢
196 ºÇÂç \fIlength\fP ¤ÎŤµ¤ò»ý¤Ä¡£
197 \fIposition\fP ¤ä \fIlength\fP ¤¬Àµ¤Ç¤Ê¤«¤Ã¤¿¤ê¿ôÃͤǤʤ«¤Ã¤¿¾ì¹ç¤Ï¡¢
200 .\"O Parentheses are used for grouping in the usual manner. The keywords
201 .\"O (match, substr, index, length) cannot be used as strings.
202 ³ç¸Ì¤ÏÄ̾ï¤Î¥°¥ë¡¼¥×²½¤Î°ÕÌ£¤ËÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¡£
203 ¥¡¼¥ï¡¼¥É (match, substr, index, length) ¤Ïʸ»úÎó¤È¤·¤ÆÍѤ¤¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
208 .\"O is invoked with exactly one argument, the following options are recognized:
211 ¤¬°ú¿ô 1 ¤Ä¤À¤±¤Çµ¯Æ°¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
212 °Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤¬Ç§¼±¤µ¤ì¤ë:
215 .\"O Print a usage message on standard output and exit successfully.
216 ɸ½à½ÐÎϤ˻ÈÍÑÊýË¡¤Î¥á¥Ã¥»¡¼¥¸¤ò½ÐÎϤ·¤ÆÀµ¾ï½ªÎ»¤¹¤ë¡£
219 .\"O Print version information on standard output then exit successfully.
220 ɸ½à½ÐÎϤ˥С¼¥¸¥ç¥ó¾ðÊó¤ò½ÐÎϤ·¤ÆÀµ¾ï½ªÎ»¤¹¤ë¡£
224 .\"O To add 1 to the shell variable
232 .\"O To print the non-directory part of the file name stored in variable
236 .\"O need not contain `/'):
239 ¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë̾¤Î¤¦¤Á¡¢
240 ¥Ç¥£¥ì¥¯¥È¥ê°Ê³°¤ÎÉôʬ¤òɽ¼¨¤¹¤ë
242 ¤ÎÃÍ¤Ë¤Ï `/' ¤¬´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¯¤Æ¤âÎɤ¤):
244 expr $bar : \'.*/\e(\^.*\e)\' \'\^|\' $a
246 .\"O Matching character `b' in the string `abc'
247 ʸ»úÎó `abc' ¤Ëʸ»ú `b' ¤ò¥Þ¥Ã¥Á¤µ¤»¤ë:
249 expr abc : 'a\e(.\e)c'
251 .\"O Finding out the index for any occurences of `c' and `z' in the string
253 ʸ»úÎó `abcdef' ¤Ë `c' ¤Þ¤¿¤Ï `z' ¤Î¤¤¤º¤ì¤«¤¬Â¸ºß¤·¤Æ¤¤¤ë°ÌÃÖ¤òõ¤¹:
257 .\"O Erroneuosly using a keyword (index) as a string
258 ¥¡¼¥ï¡¼¥É (index) ¤òʸ»úÎó¤È¤·¤ÆÍѤ¤¤Æ¤¤¤ë¸í¤Ã¤¿Îã:
262 .\"O Correctly using a keyword (index) as a string
263 ¥¡¼¥ï¡¼¥É (index) ¤òʸ»úÎó¤È¤·¤ÆÍѤ¤¤Æ¤¤¤ëÀµ¤·¤¤Îã:
265 expr index quote index d
268 .\"O Report bugs to bug-sh-utils@gnu.org.
269 .\"O Page updated by Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
270 ¥×¥í¥°¥é¥à¤Î¥Ð¥°¤Ë¤Ä¤¤¤Æ¤Ï bug-sh-utils@gnu.org ¤ËÊó¹ð¤·¤Æ¤¯¤À¤µ¤¤¡£
271 ¥Ú¡¼¥¸¤Î¹¹¿·¤Ï Ragnar Hojland Espinosa
272 <ragnar@ragnar-hojland.com> ¤¬¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£