1 This file is shift.def, from which is created shift.c.
2 It implements the builtin "shift" in Bash.
4 Copyright (C) 1987, 1989, 1991 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 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
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
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.
26 #if defined (HAVE_UNISTD_H)
30 #include "../bashansi.h"
36 $FUNCTION shift_builtin
38 The positional parameters from $N+1 ... are renamed to $1 ... If N is
39 not given, it is assumed to be 1.
42 int print_shift_error;
44 /* Shift the arguments ``left''. Shift DOLLAR_VARS down then take one
45 off of REST_OF_ARGS and place it into DOLLAR_VARS[9]. If LIST has
46 anything in it, it is a number which says where to start the
47 shifting. Return > 0 if `times' > $#, otherwise 0. */
56 times = get_numeric_arg (list, 0);
59 return (EXECUTION_SUCCESS);
62 builtin_error ("shift count must be >= 0");
63 return (EXECUTION_FAILURE);
65 else if (times > number_of_args ())
67 if (print_shift_error)
68 builtin_error ("shift count must be <= $#");
69 return (EXECUTION_FAILURE);
75 free (dollar_vars[1]);
77 for (count = 1; count < 9; count++)
78 dollar_vars[count] = dollar_vars[count + 1];
83 dollar_vars[9] = savestring (temp->word->word);
84 rest_of_args = rest_of_args->next;
85 temp->next = (WORD_LIST *)NULL;
89 dollar_vars[9] = (char *)NULL;
91 return (EXECUTION_SUCCESS);