Problem with test -r

David Laight David.Laight at ACULAB.COM
Mon Feb 13 09:00:47 UTC 2023


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.
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)


More information about the busybox mailing list