Problem with test -r
alice
alice at ayaya.dev
Mon Feb 13 09:23:56 UTC 2023
On Mon Feb 13, 2023 at 10:00 AM CET, David Laight wrote:
> From: Vladimír Macek
> > Sent: 11 February 2023 19:15
> >
> > Hi,
> >
> > I'd like to report what seems to be a bug in the busybox's test command. I
> > use the official alpine:3 docker container.
> >
> > The test -r does not return true even when the file is indeed readable
> > (testing by head command). Yes, the file has an unusual set of permissions,
> > but that does not restrict it from reading. Here's the output of the
> > interactive container shell session:
> >
> > dd72078df6d2:/task/output/files$ ls -lad . .. cnb_rate_eur_czk.csv
> > drwxrwx--- 2 setup project 4096 Feb 11 18:33 .
> > drwxr-x--- 5 setup project 4096 Feb 11 18:33 ..
> > -rw-r--r-- 1 task project 20512 Feb 11 18:33 cnb_rate_eur_czk.csv
>
> By the look of it the problem is that 'test -r' requires
> directory search access - so why not just say that.
>
> > dd72078df6d2:/task/output/files$ [ -r cnb_rate_eur_czk.csv ] && echo READABLE
> > dd72078df6d2:/task/output/files$ [[ -r cnb_rate_eur_czk.csv ]] && echo READABLE
> >
> > dd72078df6d2:/task/output/files$ which [
> > /usr/bin/[
> > dd72078df6d2:/task/output/files$ which [[
> > /usr/bin/[[
>
> The output from 'which' doesn't necessarily have any connection
> with the code any specific shell executes for a command.
> 'which' is a bourne shell script that is trying (and must fail) to
> emulate a csh builtin command.
>
> The 'test/[' command is almost certainly a shell builtin.
> The program in /usr/bin is almost never executed.
when one is using busybox ash as a shell, is /usr/bin/test (from busybox
symlink) and "builtin test" not the same code in the end (same for [)? i.e.
this case, which is probably using busybox ash (needs confirmation).
> As for '[[', IIRC that is a bash 'special' that nothing
> portable should be using.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list