bash.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
/*
* bash specific extensions
* originally provided by Karsten Fleischer
*/
#include "defs.h"
#include "path.h"
#include "io.h"
#include "builtins.h"
#include "name.h"
#ifndef BASH_MAJOR
# define BASH_MAJOR "1"
# define BASH_MINOR "0"
# define BASH_PATCH "0"
# define BASH_BUILD "0"
# define BASH_RELEASE "experimental"
#endif
extern const char bash_pre_rc[];
static char *login_files[4];
const char sh_bash1[] =
"[B?Enable brace group expansion. This option is only availabe in bash "
"compatibility mode. In ksh mode, brace group expansion is always on.]"
"[P?Do not follow symbolic links, use physical directory structure "
"instead. Only available in bash compatibility mode.]";
const char sh_bash2[] =
"[O]:?[shopt_option?\ashopt_option\a is one of the shell options accepted by "
"the \bshopt\b builtin. If \ashopt_option\a is present, \b-O\b sets "
"the value of that option; \b+O\b unsets it. If \ashopt_option\a is "
"not supplied, the names and values of the shell options accepted by "
"\bshopt\b are printed on the standard output. If the invocation "
"option is \b+O\b, the output is displayed in a format that may be "
"reused as input. Only available if invoked as \bbash\b.]"
"[01:init-file|rcfile]:[file?Execute commands from \afile\a instead of the "
"standard personal initialization file ~/.bashrc if the shell is "
"interactive. Only available if invoked as \bbash\b.]"
"[02:editing?For option compatibility with \bbash\b only. Ignored.]"
"[03:profile?Read either the system-wide startup file or any of the "
"personal initialization files. On by default for interactive "
"shells. Only available if invoked as \bbash\b.]"
"[04:posix?If invoked as \bbash\b, turn on POSIX compatibility. \bBash\b in "
"POSIX mode is not the same as \bksh\b.]"
"[05:version?Print version number and exit.]";
const char sh_optshopt[] =
"+[-1c?\n@(#)$Id: shopt (AT&T Research) 2003-02-13 $\n]"
"[-author?Karsten Fleischer <K.Fleischer@omnium.de>]"
"[+DESCRIPTION?\bshopt\b sets or unsets variables controlling optional shell "
"behavior. With no options, or with the \b-p\b option, a list of all "
"settable options is displayed, with an indication of whether or not "
"each is set.]"
"[p?Causes output to be displayed in a form that may be reused as input.]"
"[s?Set each \aoptname\a.]"
"[u?Unset each \aoptname\a.]"
"[q?Suppress output (quiet mode). The return status indicates whether the "
"\aoptname\a is set or unset. If multiple \aoptname\a arguments are "
"given with \b-q\b, the return status is zero if all \aoptname\as are "
"enabled; non-zero otherwise.]"
"[o?Restricts the values of \aoptname\a to be those defined for the \b-o\b "
"option to the set builtin.]"
"[+?If either \b-s\b or \b-u\b is used with no \aoptname\a arguments, the "
"display is limited to those options which are set or unset.]"
"[+?\bshopt\b supports all bash options. Some settings do not have any effect "
"or are are always on and cannot be changed.]"
"[+?The value of \aoptname\a must be one of the following:]{"
"[+cdable_vars?If set, arguments to the \bcd\b command are "
"assumed to be names of variables whose values are to "
"be used if the usual \bcd\b proceeding fails.]"
"[+cdspell?Currently ignored.]"
"[+checkhash?Always on.]"
"[+checkwinsize?Currently ignored.]"
"[+cmdhist?Always on.]"
"[+dotglob?If set, include filenames beginning with a \b.\b "
"in the results of pathname expansion.]"
"[+execfail?Always on.]"
"[+expand_aliases?Always on.]"
"[+extglob?Enable extended pattern matching features.]"
"[+histappend?Always on.]"
"[+histreedit?If set and an edit mode is selected, the user "
"is given the opportunity to re-edit a failed history "
"substitution.]"
"[+histverify?If set and an edit mode is selected, the result "
"of a history substitution will not be executed "
"immediately but be placed in the edit buffer for "
"further modifications.]"
"[+hostcomplete?Currently ignored.]"
"[+huponexit?Currently ignored.]"
"[+interactive_comments?Always on.]"
"[+lithist?Always on.]"
"[+login_shell?This option is set if the shell is started as "
"a login shell. The value cannot be changed.]"
"[+mailwarn?Currently ignored.]"
"[+no_empty_cmd_completion?Always on.]"
"[+nocaseglob?Match filenames in a case-insensitive fashion "
"when performing filename expansion.]"
"[+nullglob?Allows filename patterns which match no files to "
"expand to a null string, rather than themselves.]"
"[+progcomp?Currently ignored.]"
"[+promptvars?Currently ignored.]"
"[+restricted_shell?This option is set if the shell is started "
"as a restricted shell. The value cannot be changed. "
"It is not reset during execution of startup files, "
"allowing the startup files to determine whether the "
"shell is restricted.]"
"[+shift_verbose?Currently ignored.]"
"[+sourcepath?If set, the \b.\b builtin uses the value of PATH "
"to find the directory containing the file supplied "
"as an argument.]"
"[+xpg_echo?If set, the \becho\b and \bprint\b builtins "
"expand backslash-escape sequences.]"
"}"
"\n"
"\n[optname ...]\n"
"\n"
"[+EXIT STATUS?]{"
"[+?The return status when listing options is zero if all \aoptnames\a "
"are enabled, non-zero otherwise. When setting or unsetting options, "
"the return status is zero unless an \aoptname\a is not a valid shell "
"option.]"
"}"
"[+SEE ALSO?\bset\b(1)]"
;
/* GLOBIGNORE discipline. Turn on SH_DOTGLOB on set, turn off on unset. */
{
if(val)
else
}
/* FUNCNAME discipline */
struct funcname
{
};
{
/* bash silently returns with an error when FUNCNAME is set,
unsetting FUNCNAME is allowed */
}
#define SET_SET 1
#define SET_UNSET 2
#define SET_NOARGS 4
/* shopt builtin */
{
int n, f, ret=0;
#if SHOPT_RAWONLY
#endif
{
switch(n)
{
case 'p':
break;
case 's':
case 'u':
{
error_info.errors++;
}
break;
case 'q':
quietflag=1;
break;
case 'o':
oflag=1;
break;
case ':':
continue;
case '?':
return(-1);
}
}
if(error_info.errors)
if(argc==0)
{
/* no args, -s => mask=current options, -u mask=~(current options)
else mask=all bits */
for(n=0;n<4;n++)
else
}
while(argc>0)
{
f=1;
if(n<=0||(setflag
||(oflag&&(n&SH_BASHOPT)))
{
error_info.errors++;
ret=1;
}
else if(f)
else
argc--;
}
{
{
{
}
for(n=0;n<4;n++)
}
for(n=0;n<4;n++)
}
{
for(n=0;n<4;n++)
}
return(ret);
}
/* mode = 0: init, called two times
before parsing shell args with SH_PREINIT state turned on
second time after sh_init() is through and with SH_PREINIT state turned off
mode > 1: re-init
mode < 0: shutdown
*/
{
if(mode>0)
goto reinit;
if(mode < 0)
{
/* termination code */
return;
}
if(sh_isstate(SH_PREINIT))
{ /* pre-init stage */
if(sh_isoption(SH_RESTRICTED))
else
else
/* add builtins */
/* set up some variables needed for --version
* needs to go here because --version option is parsed before the init script.
*/
{
char *argv[7];
argv[0] = BASH_MAJOR;
argv[6] = 0;
}
return;
}
/* rest of init stage */
/* restrict BASH_ENV */
{
}
/* open GLOBIGNORE node */
{
}
/* set startup files */
n=0;
{
if(!sh_isoption(SH_POSIX))
{
login_files[n++] = (char*)e_bash_profile;
login_files[n++] = (char*)e_bash_login;
}
login_files[n++] = (char*)e_profile;
}
if(xtrace)
if(verbose)
}