Problem description
Quoting a variable leads to no glob expansion even outside the quotes.
Steps to reproduce
Install Termux from scratch (bash 4 and readline 7 will be installed)
Run:
touch "${HOME}/hello.txt"
ls "${HOME}"/*.txt
Output:
/data/data/com.termux/files/home/hello.txt
Upgrade (_pkg upgrade_) and restart Termux; bash 5 and readline 8 will be installed)
Run:
touch "${HOME}/hello.txt"
ls "${HOME}"/*.txt
Output:
ls: /data/data/com.termux/files/home/*.txt: No such file or directory
Run:
touch "${HOME}/hello.txt"
ls ${HOME}/*.txt
Output:
/data/data/com.termux/files/home/hello.txt
Expected behavior
The command _ls "${HOME}"/*.txt_ works in Bash 5 too
Additional information
I don't know whether this is a bug or an intended behaviour. I have (quickly) read the changelogs for Bash and Readline and found nothing. I have built Bash 5 on Ubuntu 18.04 using the installed Readline 7 and the command works as expected.
I have built Bash 5 on Ubuntu 18.04 using the installed Readline 7 and the command works as expected.
You cannot build bash with readline 7. It will use own version of readline if your system's version is not compatible. Also readline has nothing to do with globs and you likely didn't downloaded latest patches for bash.
Caused by http://mirrors.kernel.org/gnu/bash/bash-5.0-patches/bash50-001. If bash built without this patch, issue is not reproducible.
You cannot build bash with readline 7. It will use own version of readline if your system's version is not compatible.
That I didn't know :)
you likely didn't downloaded latest patches for bash.
I didn't use any patch, no
Figured out. Problem is neither in http://mirrors.kernel.org/gnu/bash/bash-5.0-patches/bash50-001 or bash 5 itself.
Bug is Termux-specific because Termux is located at /data/data/com.termux but bash does not have access for /data and therefore fails to properly expand the glob. This happens after changes introduced in http://mirrors.kernel.org/gnu/bash/bash-5.0-patches/bash50-001.
11784 openat(AT_FDCWD, "/data", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = -1 EACCES (Permission denied)
Can be verified by:
[~]:$ termux-chroot
[/home]:$ ls "${HOME}"/*.txt
ls: cannot access '/data/data/com.termux/files/home/*.txt': No such file or directory
[/home]:$ export HOME=/home
[~]:$ ls "${HOME}"/*.txt
/home/b.txt /home/hello.txt
[~]:$
[tom@archlinux ~]$ bash --version
GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[tom@archlinux ~]$ stat /home/
File: /home/
Size: 3488 Blocks: 7 IO Block: 4096 directory
Device: 802h/2050d Inode: 2903 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-03-03 10:02:41.464980999 +0800
Modify: 2018-09-19 16:39:32.964751119 +0800
Change: 2019-03-03 10:05:48.741842423 +0800
Birth: -
[tom@archlinux ~]$ ls ~/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls "$HOME"/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls $HOME/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ sudo chmod o-r /home/
[tom@archlinux ~]$ stat /home/
File: /home/
Size: 3488 Blocks: 7 IO Block: 4096 directory
Device: 802h/2050d Inode: 2903 Links: 3
Access: (0751/drwxr-x--x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-03-03 10:02:41.464980999 +0800
Modify: 2018-09-19 16:39:32.964751119 +0800
Change: 2019-03-03 10:07:52.999916254 +0800
Birth: -
[tom@archlinux ~]$ ls ~/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls "$HOME"/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls $HOME/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$
[tom@archlinux ~]$ bash --version
GNU bash, version 5.0.2(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[tom@archlinux ~]$ stat /home/
File: /home/
Size: 3488 Blocks: 7 IO Block: 4096 directory
Device: 802h/2050d Inode: 2903 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-03-03 10:02:41.464980999 +0800
Modify: 2018-09-19 16:39:32.964751119 +0800
Change: 2019-03-03 10:10:00.413285624 +0800
Birth: -
[tom@archlinux ~]$ ls ~/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls "$HOME"/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ ls $HOME/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$ sudo chmod o-r /home/
[tom@archlinux ~]$ stat /home/
File: /home/
Size: 3488 Blocks: 7 IO Block: 4096 directory
Device: 802h/2050d Inode: 2903 Links: 3
Access: (0751/drwxr-x--x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-03-03 10:11:15.762301623 +0800
Modify: 2018-09-19 16:39:32.964751119 +0800
Change: 2019-03-03 10:11:29.708726517 +0800
Birth: -
[tom@archlinux ~]$ ls ~/*.txt
ls: cannot access '/home/tom/*.txt': No such file or directory
[tom@archlinux ~]$ ls "$HOME"/*.txt
ls: cannot access '/home/tom/*.txt': No such file or directory
[tom@archlinux ~]$ ls $HOME/*.txt
/home/tom/hello.txt
[tom@archlinux ~]$
This should be deemed as an upstream regression.
Another test case is with ~.
$ bash -c 'ls ~/*'
ls: cannot access '/data/data/com.termux/files/home/*': No such file or directory
My backups are broken, I'll wait for a day, then if it's not fixed implement a workaround.
AKA "me too"
Looks like this bug is known and being worked on upstream.
Here are some bash-bugs mailing list references:
Personally, I've worked around this by changing a "$x"/* to a "${x/$PWD/.}"/*. Of course this workaround only works if the glob'd path just happens to fall under a readable $PWD. Now I feel lucky that I didn't have to drop the quotes.
Bash 5.0.3 should fix the globbing problem.
Most helpful comment
Looks like this bug is known and being worked on upstream.
Here are some bash-bugs mailing list references:
Personally, I've worked around this by changing a
"$x"/*to a"${x/$PWD/.}"/*. Of course this workaround only works if the glob'd path just happens to fall under a readable$PWD. Now I feel lucky that I didn't have to drop the quotes.