]> git.ipfire.org Git - thirdparty/bash.git/blob - builtins/let.def
fd037cd96800512c24a3aecaa85ef94521a96b86
[thirdparty/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, plus
33 !, ~ logical and bitwise negation
34 *, /, % multiplication, division, remainder
35 +, - addition, subtraction
36 <<, >> left and right bitwise shifts
37 <=, >=, <, > comparison
38 ==, != equality, inequality
39 & bitwise AND
40 ^ bitwise XOR
41 | bitwise OR
42 && logical AND
43 || logical OR
44 expr ? expr : expr
45 conditional expression
46 =, *=, /=, %=,
47 +=, -=, <<=, >>=,
48 &=, ^=, |= assignment
49
50 Shell variables are allowed as operands. The name of the variable
51 is replaced by its value (coerced to a long integer) within
52 an expression. The variable need not have its integer attribute
53 turned on to be used in an expression.
54
55 Operators are evaluated in order of precedence. Sub-expressions in
56 parentheses are evaluated first and may override the precedence
57 rules above.
58
59 If the last ARG evaluates to 0, let returns 1; 0 is returned
60 otherwise.
61 $END
62
63 #include <config.h>
64
65 #if defined (HAVE_UNISTD_H)
66 # ifdef _MINIX
67 # include <sys/types.h>
68 # endif
69 # include <unistd.h>
70 #endif
71
72 #include "../shell.h"
73 #include "common.h"
74
75 /* Arithmetic LET function. */
76 int
77 let_builtin (list)
78 WORD_LIST *list;
79 {
80 long ret;
81 int expok;
82
83 if (list == 0)
84 {
85 builtin_error ("expression expected");
86 return (EXECUTION_FAILURE);
87 }
88
89 for (; list; list = list->next)
90 {
91 ret = evalexp (list->word->word, &expok);
92 if (expok == 0)
93 return (EXECUTION_FAILURE);
94 }
95
96 return ((ret == 0L) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
97 }
98
99 #ifdef INCLUDE_UNUSED
100 int
101 exp_builtin (list)
102 WORD_LIST *list;
103 {
104 char *exp;
105 int ret, expok;
106
107 if (list == 0)
108 {
109 builtin_error ("expression expected");
110 return (EXECUTION_FAILURE);
111 }
112
113 exp = string_list (list);
114 ret = evalexp (exp, &expok);
115 (void)free (exp);
116 return (((ret == 0L) || (expok == 0)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
117 }
118 #endif