$BUILTIN mapfile
$FUNCTION mapfile_builtin
$SHORT_DOC mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
-Read lines from the standard input into an array variable.
+Read lines from the standard input into an indexed array variable.
-Read lines from the standard input into the array variable ARRAY, or from
-file descriptor FD if the -u option is supplied. The variable MAPFILE is
-the default ARRAY.
+Read lines from the standard input into the indexed array variable ARRAY, or
+from file descriptor FD if the -u option is supplied. The variable MAPFILE
+is the default ARRAY.
Options:
-n count Copy at most COUNT lines. If COUNT is 0, all lines are copied.
assigning to it.
Exit Status:
-Returns success unless an invalid option is given or ARRAY is readonly.
+Returns success unless an invalid option is given or ARRAY is readonly or
+not an indexed array.
$END
$BUILTIN readarray
#endif
#include "bashansi.h"
+#include "bashintl.h"
#include <stdio.h>
#include <errno.h>
execlen += 2;
execstr = xmalloc (execlen);
- flags = 0;
+ flags = SEVAL_NOHIST;
#if 0
if (interactive)
- flags |= SEVAL_NOHIST|SEVAL_INTERACT;
+ flags |= SEVAL_INTERACT;
#endif
snprintf (execstr, execlen, "%s %d", callback, current_index);
return parse_and_execute(execstr, NULL, flags);
entry = find_or_make_array_variable (array_name, 1);
if (entry == 0 || readonly_p (entry) || noassign_p (entry))
{
- if (readonly_p (entry))
+ if (entry && readonly_p (entry))
err_readonly (array_name);
return (EXECUTION_FAILURE);
}
+ else if (array_p (entry) == 0)
+ {
+ builtin_error (_("%s: not an indexed array"), array_name);
+ return (EXECUTION_FAILURE);
+ }
+
if (flags & MAPF_CLEARARRAY)
array_flush (array_cell (entry));
break;
case 'c':
code = legal_number (list_optarg, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned)intval)
+ if (code == 0 || intval <= 0 || intval != (unsigned)intval)
{
builtin_error (_("%s: invalid callback quantum"), list_optarg);
return (EXECUTION_FAILURE);