1 This file is shift.def, from which is created shift.c.
2 It implements the builtin "shift" in Bash.
4 Copyright (C) 1987-2009 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash 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 Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>.
25 #if defined (HAVE_UNISTD_H)
27 # include <sys/types.h>
32 #include "../bashansi.h"
33 #include "../bashintl.h"
39 $FUNCTION shift_builtin
41 Shift positional parameters.
43 Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
44 not given, it is assumed to be 1.
47 Returns success unless N is negative or greater than $#.
50 int print_shift_error;
52 /* Shift the arguments ``left''. Shift DOLLAR_VARS down then take one
53 off of REST_OF_ARGS and place it into DOLLAR_VARS[9]. If LIST has
54 anything in it, it is a number which says where to start the
55 shifting. Return > 0 if `times' > $#, otherwise 0. */
64 if (get_numeric_arg (list, 0, ×) == 0)
65 return (EXECUTION_FAILURE);
68 return (EXECUTION_SUCCESS);
71 sh_erange (list ? list->word->word : NULL, _("shift count"));
72 return (EXECUTION_FAILURE);
74 else if (times > number_of_args ())
76 if (print_shift_error)
77 sh_erange (list ? list->word->word : NULL, _("shift count"));
78 return (EXECUTION_FAILURE);
84 free (dollar_vars[1]);
86 for (count = 1; count < 9; count++)
87 dollar_vars[count] = dollar_vars[count + 1];
92 dollar_vars[9] = savestring (temp->word->word);
93 rest_of_args = rest_of_args->next;
94 temp->next = (WORD_LIST *)NULL;
98 dollar_vars[9] = (char *)NULL;
100 return (EXECUTION_SUCCESS);