1 This file is let.def
, from which is created let.c.
2 It implements the builtin
"let" in Bush.
4 Copyright (C
) 1987-2009 Free Software Foundation
, Inc.
6 This file is part of GNU Bush
, the Bourne Again SHell.
8 Bush is free software
: you can redistribute it and
/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation
, either version
3 of the License
, or
11 (at your option
) any later version.
13 Bush is distributed in the hope that it will be useful
,
14 but WITHOUT ANY WARRANTY
; without even the implied warranty of
15 MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bush. If not
, see
<http
://www.gnu.org
/licenses
/>.
24 $SHORT_DOC let arg
[arg ...
]
25 Evaluate arithmetic expressions.
27 Evaluate each ARG as an arithmetic expression. Evaluation is done in
28 fixed
-width integers with no check for overflow
, though division by
0
29 is trapped and flagged as an error. The following list of operators is
30 grouped into levels of equal
-precedence operators. The levels are listed
31 in order of decreasing precedence.
33 id
++, id
-- variable post
-increment
, post
-decrement
34 ++id
, --id variable pre
-increment
, pre
-decrement
35 -, + unary minus
, plus
36 !, ~ logical and bitwise negation
38 *, /, % multiplication
, division
, remainder
39 +, - addition
, subtraction
40 <<, >> left and right bitwise shifts
41 <=, >=, <, > comparison
42 ==, != equality
, inequality
54 Shell variables are allowed as operands. The name of the variable
55 is replaced by its
value (coerced to a fixed
-width integer
) within
56 an expression. The variable need not have its integer attribute
57 turned on to be used in an expression.
59 Operators are evaluated in order of precedence. Sub
-expressions in
60 parentheses are evaluated first and may override the precedence
64 If the last ARG evaluates to
0, let returns
1; let returns
0 otherwise.
69 #if
defined (HAVE_UNISTD_H
)
71 # include
<sys
/types.h
>
76 #include
"../src/bushintl.h"
78 #include
"../src/shell.h"
81 /* Arithmetic LET function.
*/
91 /* Skip over leading `
--' argument. */
92 if (list && list->word && ISOPTION (list->word->word, '-'))
97 builtin_error (_("expression expected"));
98 return (EXECUTION_FAILURE);
101 for (; list; list = list->next)
103 ret = evalexp (list->word->word, EXP_EXPANDED, &expok);
105 return (EXECUTION_FAILURE);
108 return ((ret == 0) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
111 #ifdef INCLUDE_UNUSED
122 builtin_error (_("expression expected"));
123 return (EXECUTION_FAILURE);
126 exp = string_list (list);
127 ret = evalexp (exp, EXP_EXPANDED, &expok);
129 return (((ret == 0) || (expok == 0)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);