aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin_set.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-07-12 15:43:32 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-07-12 15:43:32 -0700
commit387ec5c06ad43f2aa0276be039522bd678cac4db (patch)
treebaee5b9a8914af1bbb75f1a927a71a2e3d0bc442 /builtin_set.cpp
parentdcc043df3b4d3f2f8aae5d8e8fe50051f78ce848 (diff)
set: Don't create empty var when erasing index
When using `set -e foo[1]` to erase an index, if the variable doesn't already exist, return 1 instead of creating it as an empty variable.
Diffstat (limited to 'builtin_set.cpp')
-rw-r--r--builtin_set.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/builtin_set.cpp b/builtin_set.cpp
index e74cc6d6..043bd522 100644
--- a/builtin_set.cpp
+++ b/builtin_set.cpp
@@ -712,33 +712,42 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
const env_var_t dest_str = env_get_string(dest, scope);
if (! dest_str.missing())
+ {
tokenize_variable_array(dest_str, result);
-
- for (; woptind<argc; woptind++)
+ }
+ else if (erase)
{
- if (!parse_index(indexes, argv[woptind], dest, result.size()))
- {
- builtin_print_help(parser, argv[0], stderr_buffer);
- retcode = 1;
- break;
- }
-
- size_t idx_count = indexes.size();
- size_t val_count = argc-woptind-1;
+ retcode = 1;
+ }
- if (!erase)
+ if (!retcode)
+ {
+ for (; woptind<argc; woptind++)
{
- if (val_count < idx_count)
+ if (!parse_index(indexes, argv[woptind], dest, result.size()))
{
- append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), argv[0]);
builtin_print_help(parser, argv[0], stderr_buffer);
- retcode=1;
+ retcode = 1;
break;
}
- if (val_count == idx_count)
+
+ size_t idx_count = indexes.size();
+ size_t val_count = argc-woptind-1;
+
+ if (!erase)
{
- woptind++;
- break;
+ if (val_count < idx_count)
+ {
+ append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), argv[0]);
+ builtin_print_help(parser, argv[0], stderr_buffer);
+ retcode=1;
+ break;
+ }
+ if (val_count == idx_count)
+ {
+ woptind++;
+ break;
+ }
}
}
}