Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14348

DIRSTACK[0] contains literal "~"

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From <jeremy.richards@ngc.com>
Newsgroups gnu.bash.bug
Subject DIRSTACK[0] contains literal "~"
Date Thu, 12 Jul 2018 17:38:53 -0600
Lines 41
Approved bug-bash@gnu.org
Message-ID <mailman.3686.1531792266.1292.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain
X-Trace usenet.stanford.edu 1531792268 15545 208.118.235.17 (17 Jul 2018 01:51:08 GMT)
X-Complaints-To action@cs.stanford.edu
To <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 134.223.120.78
X-Mailman-Approved-At Mon, 16 Jul 2018 21:51:06 -0400
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14348

Show key headers only | View raw


Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic
uname output: Linux Cyborg.localdomain 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.2
Patch Level: 46
Release Status: release

Description:
    I noticed some strange behavior in the DIRSTACK variable (used in pushd/popd). 
    `declare -p DIRSTACK`
    shows the list of current directories on the stack, as expected. ${DIRSTACK[@]:1} show correctly expanded paths, i.e., “pushd ~/Jenkins” will correctly store "/home/jeremy/jenkins"
    However, ${DIRSTACK[0]} does NOT have this behavior, and will encode a literal tilde, e.g., "~/jenkins"
    This behavior is obfuscated by 
    dirs -v 
    and
    dirs -l
    The first option will *always* display the stack with ~ instead of $HOME, and the second option will *always* display $HOME instead of ~.

    This means, for instance, that rearranging the order of the DIRSTACK array can produce invalid directory targets. 


Repeat-By:
    mkdir -p ~/some/test/path
    cd ~/some/test/path
    pushd ~/some/test/
    pushd ~/some/
    declare -p DIRSTACK
    #output will show literal ~ in ${DIRSTACK[0]}
    pushd +0 #works, but I believe this is because it just says "don't need to move"
    pushd +1 #works
    DIRSTACK[1]=${DIRSTACK[0]}
    pushd +1 #fails, "no such file or directory" because ~ isn't expanded

Fix:
    Don't store ~ in ${DIRSTACK[0]}. pushd ~/some/ will be correctly expanded, this just needs to be implemented for the current directory as well. I know you probably wanted a technical fix here, sorry.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

DIRSTACK[0] contains literal "~" <jeremy.richards@ngc.com> - 2018-07-12 17:38 -0600

csiph-web