/*
Please use git log for copyright holder and year information
This file is part of libbash.
libbash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
libbash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libbash. If not, see .
*/
///
/// \file unset_builtin.h
/// \brief implementation for the unset builtin
///
#include "builtins/unset_builtin.h"
#include
#include "core/interpreter.h"
int unset_builtin::exec(const std::vector& bash_args)
{
if(bash_args.empty())
return 0;
if(bash_args[0] == "-f")
for_each(bash_args.begin() + 1,
bash_args.end(),
std::bind(&interpreter::unset_function, &_walker, std::placeholders::_1));
else
/* POSIX says if neither -f nor -v is specified, name refers to a variable;
* if a variable by that name does not exist, it is unspecified whether a
* function by that name, if any, shall be unset.
*
* >=bash-4.1: without options, unset first tries to unset a variable, and
* if that fails, tries to unset a function.
* (We haven't checked bash-4.0)
*
* bash-3.2: if no options are supplied, or the -v option is given, each
* name refers to a shell variable.
*
* We addhere to bash-3.2
* */
for_each(bash_args.front() == "-v" ? bash_args.begin() + 1 : bash_args.begin(),
bash_args.end(),
[&](const std::string& name) { _walker.unset(name); });
return 0;
}