Skip to content

Commit

Permalink
Accept 'shopt -s expand_aliases' as a noop.
Browse files Browse the repository at this point in the history
Add more spec test cases for alias.
  • Loading branch information
Andy Chu committed Sep 4, 2018
1 parent f6d19b5 commit 29de900
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/state.py
Expand Up @@ -154,6 +154,8 @@ def __init__(self, mem):
# these.
self.nullglob = False
self.failglob = False
# No-op for bash compatibility. We always expand aliases.
self.expand_aliases = False

#
# OSH-specific options that are not yet implemented.
Expand Down Expand Up @@ -251,7 +253,7 @@ def SetOption(self, opt_name, b):
new_val = runtime.Str(':'.join(names))
self.mem.InternalSetGlobal('SHELLOPTS', new_val)

SHOPT_OPTIONS = ('nullglob', 'failglob')
SHOPT_OPTIONS = ('nullglob', 'failglob', 'expand_aliases')

def SetShoptOption(self, opt_name, b):
""" For shopt -s/-u. """
Expand Down
17 changes: 16 additions & 1 deletion spec/alias.test.sh
Expand Up @@ -4,7 +4,7 @@
#
# http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_03_01
#
# Bash is the only one that doesn't support aliases!
# Bash is the only one that doesn't support aliases by default!

#### Basic alias
shopt -s expand_aliases # bash requires this
Expand All @@ -18,6 +18,21 @@ hi
expected failure
## END

#### define and use alias on a single line
shopt -s expand_aliases
alias e=echo; e one # this is not alias-expanded because we parse lines at once
e two; e three
## STDOUT:
two
three
## END

#### alias can override builtin
shopt -s expand_aliases
alias echo='echo foo'
echo bar
## stdout: foo bar

#### defining multiple aliases, then unalias
shopt -s expand_aliases # bash requires this
x=x
Expand Down

0 comments on commit 29de900

Please sign in to comment.