fdb3a6f6d8a83a0296bb59b83d4c6c49abeeb762
[platform/upstream/bash.git] / builtins / let.def
1 This file is let.def, from which is created let.c.
2 It implements the builtin "let" in Bash.
3
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
5
6 This file is part of GNU Bash, the Bourne Again SHell.
7
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
11 version.
12
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING.  If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 $BUILTIN let
23 $FUNCTION let_builtin
24 $PRODUCES let.c
25 $SHORT_DOC let arg [arg ...]
26 Each ARG is an arithmetic expression to be evaluated.  Evaluation
27 is done in long integers with no check for overflow, though division
28 by 0 is trapped and flagged as an error.  The following list of
29 operators is grouped into levels of equal-precedence operators.
30 The levels are listed in order of decreasing precedence.
31
32         -               unary minus
33         !               logical NOT
34         * / %           multiplication, division, remainder
35         + -             addition, subtraction
36         <= >= < >       comparison
37         == !=           equality inequality
38         =               assignment
39
40 Shell variables are allowed as operands.  The name of the variable
41 is replaced by its value (coerced to a long integer) within
42 an expression.  The variable need not have its integer attribute
43 turned on to be used in an expression.
44
45 Operators are evaluated in order of precedence.  Sub-expressions in
46 parentheses are evaluated first and may override the precedence
47 rules above.
48
49 If the last ARG evaluates to 0, let returns 1; 0 is returned
50 otherwise.
51 $END
52
53 #include "../shell.h"
54
55 /* Arithmetic LET function. */
56 let_builtin (list)
57      WORD_LIST *list;
58 {
59   long ret = 0L;
60
61   if (!list)
62     {
63       builtin_error ("argument (expression) expected");
64       return (EXECUTION_FAILURE);
65     }
66
67   while (list)
68     {
69       ret = evalexp (list->word->word);
70       list = list->next;
71     }
72
73   if (ret == 0L)
74     return (EXECUTION_FAILURE);
75   else
76     return (EXECUTION_SUCCESS);
77 }