Skip to content

Commit

Permalink
Fix incorrect handling of IFS and restore its original value
Browse files Browse the repository at this point in the history
Close #4
sgleizes committed Jan 14, 2022

Verified

This commit was signed with the committer’s verified signature.
sgleizes Stéphane Gleizes
1 parent 86fbd48 commit 295368f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion xsh.sh
Original file line number Diff line number Diff line change
@@ -77,14 +77,18 @@ xsh() {
# with '_' to avoid potential conflicts.
local _XSH_COMMAND=
local _XSH_LOAD_UNITS=
local _err=0 _begin= _elapsed=
local _err=0 _oldifs= _begin= _elapsed=

# Replace 'sh' by 'posix' if it is the current shell.
# This is not done post option processing since AFAIK it would require
# to use both sed and command substitution, which would have a significant
# performance impact. User-supplied values must use 'posix' instead of 'sh'.
[ "$XSH_SHELLS" = 'sh' ] && XSH_SHELLS='posix'

# Save IFS value and prevent it from propagating to sourced units.
_oldifs="$IFS"; ${IFS+':'} unset _oldifs
unset IFS

# Enter the "real" posix zone.
# In the scope of the current function, zsh emulation is not active so
# we must make sure that the code executed here is compliant with the POSIX
@@ -111,6 +115,9 @@ xsh() {
_xsh_log "$_XSH_RUNCOM runcom [${_elapsed}ms]"
fi

# Restore original IFS value.
IFS="$_oldifs"; ${_oldifs+':'} unset IFS

# Set the root _XSH_LEVEL after the init unit has been sourced to log it at runcom level.
[ "$_XSH_COMMAND" = 'init' ] && _XSH_LEVEL='+'
return $_err

0 comments on commit 295368f

Please sign in to comment.