mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Load 'r' and 'history' default aliases on interactive only
These two default aliases are useful on interactive shells. In scripts, they interfere with possible function or command names. As of this commit, these final two default aliases are only loaded for interactive shells, leaving zero default aliases for scripts. This completes the project to get rid of misguided default aliases. src/cmd/ksh93/include/shtable.h, src/cmd/ksh93/data/aliases.c: src/cmd/ksh93/sh/init.c: - Add empty alias table shtab_noaliases[] for scripts. - Rename inittree() to sh_inittree() and make it external. - nv_init(), sh_reinit(): Initialise empty alias tree for scripts. src/cmd/ksh93/sh/main.c: sh_main(): - If interactive, reinitialise alias tree for interactive shells. src/cmd/ksh93/tests/alias.sh: - To test default alias removal, launch shell with -i.
This commit is contained in:
parent
a42ac7e77a
commit
17f81ebedb
7 changed files with 23 additions and 29 deletions
|
@ -24,7 +24,7 @@
|
|||
#include "FEATURE/dynamic"
|
||||
|
||||
/*
|
||||
* This is the table of built-in aliases. These should be exported.
|
||||
* Table of built-in aliases for interactive shells.
|
||||
*/
|
||||
|
||||
const struct shtable2 shtab_aliases[] =
|
||||
|
@ -34,3 +34,12 @@ const struct shtable2 shtab_aliases[] =
|
|||
"", 0, (char*)0
|
||||
};
|
||||
|
||||
/*
|
||||
* Empty table of built-in aliases for non-interactive shells.
|
||||
*/
|
||||
|
||||
const struct shtable2 shtab_noaliases[] =
|
||||
{
|
||||
"", 0, (char*)0
|
||||
};
|
||||
|
||||
|
|
|
@ -56,10 +56,12 @@ extern const Shtable_t shtab_options[];
|
|||
extern const Shtable_t shtab_attributes[];
|
||||
extern const struct shtable2 shtab_variables[];
|
||||
extern const struct shtable2 shtab_aliases[];
|
||||
extern const struct shtable2 shtab_noaliases[];
|
||||
extern const struct shtable2 shtab_signals[];
|
||||
extern const struct shtable3 shtab_builtins[];
|
||||
extern const Shtable_t shtab_reserved[];
|
||||
extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
|
||||
extern int sh_lookopt(const char*, int*);
|
||||
extern Dt_t *sh_inittree(Shell_t*, const struct shtable2*);
|
||||
|
||||
#endif /* SH_TABLE_H */
|
||||
|
|
|
@ -217,7 +217,6 @@ static int lctype;
|
|||
static int nbltins;
|
||||
static void env_init(Shell_t*);
|
||||
static Init_t *nv_init(Shell_t*);
|
||||
static Dt_t *inittree(Shell_t*,const struct shtable2*);
|
||||
static int shlvl;
|
||||
|
||||
#ifdef _WINIX
|
||||
|
@ -1561,7 +1560,7 @@ int sh_reinit(char *argv[])
|
|||
nv_delete(np,dp,NV_NOFREE);
|
||||
}
|
||||
dtclose(shp->alias_tree);
|
||||
shp->alias_tree = inittree(shp,shtab_aliases);
|
||||
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
|
||||
shp->last_root = shp->var_tree;
|
||||
shp->inuse_bits = 0;
|
||||
if(shp->userinit)
|
||||
|
@ -1760,7 +1759,7 @@ static Init_t *nv_init(Shell_t *shp)
|
|||
shp->nvfun.last = (char*)shp;
|
||||
shp->nvfun.nofree = 1;
|
||||
ip->sh = shp;
|
||||
shp->var_base = shp->var_tree = inittree(shp,shtab_variables);
|
||||
shp->var_base = shp->var_tree = sh_inittree(shp,shtab_variables);
|
||||
SHLVL->nvalue.ip = &shlvl;
|
||||
ip->IFS_init.hdr.disc = &IFS_disc;
|
||||
ip->PATH_init.disc = &RESTRICTED_disc;
|
||||
|
@ -1853,9 +1852,9 @@ static Init_t *nv_init(Shell_t *shp)
|
|||
(MCHKNOD)->nvalue.lp = (&sh_mailchk);
|
||||
(OPTINDNOD)->nvalue.lp = (&shp->st.optindex);
|
||||
/* set up the seconds clock */
|
||||
shp->alias_tree = inittree(shp,shtab_aliases);
|
||||
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
|
||||
shp->track_tree = dtopen(&_Nvdisc,Dtset);
|
||||
shp->bltin_tree = inittree(shp,(const struct shtable2*)shtab_builtins);
|
||||
shp->bltin_tree = sh_inittree(shp,(const struct shtable2*)shtab_builtins);
|
||||
shp->fun_tree = dtopen(&_Nvdisc,Dtoset);
|
||||
dtview(shp->fun_tree,shp->bltin_tree);
|
||||
nv_mount(DOTSHNOD, "type", shp->typedict=dtopen(&_Nvdisc,Dtoset));
|
||||
|
@ -1878,7 +1877,7 @@ static Init_t *nv_init(Shell_t *shp)
|
|||
* initialize name-value pairs
|
||||
*/
|
||||
|
||||
static Dt_t *inittree(Shell_t *shp,const struct shtable2 *name_vals)
|
||||
Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
|
||||
{
|
||||
register Namval_t *np;
|
||||
register const struct shtable2 *tp;
|
||||
|
|
|
@ -176,6 +176,8 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
|||
{
|
||||
sh_onoption(SH_BGNICE);
|
||||
sh_onoption(SH_RC);
|
||||
free(shp->alias_tree);
|
||||
shp->alias_tree = sh_inittree(shp,shtab_aliases);
|
||||
}
|
||||
if(!sh_isoption(SH_RC) && (sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX)
|
||||
#if SHOPT_REMOTE
|
||||
|
|
|
@ -110,7 +110,7 @@ unalias foo
|
|||
unalias foo && err_exit 'unalias should return non-zero when a previously set alias is unaliased twice'
|
||||
|
||||
# Removing a predefined alias should work without an error from free(3)
|
||||
$SHELL -c 'unalias history' 2> /dev/null || err_exit 'removing a predefined alias does not work'
|
||||
$SHELL -i -c 'unalias history' 2> /dev/null || err_exit 'removing a predefined alias does not work'
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue