FS#60481 - Inappropriate response from ls with non-existent directory with a wildcard (*)

Attached to Project: Arch Linux
Opened by Earnie Boyd (Earnie) - Thursday, 18 October 2018, 18:39 GMT
Last edited by Eli Schwartz (eschwartz) - Thursday, 18 October 2018, 18:44 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To No-one
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
The ls command gives an inappropriate response when given a `/non-existent/directory/*` argument. It is expected that the described argument would give a `No such file or directory` response and set the exit status to 2. Instead it lists the current working directory and sets exit status to 0. This can give scripts expecting to execute one path or another based on the results false positives.

Additional info:
* package version(s)
coreutils-8.29-1

* config and/or log files etc.
none

Steps to reproduce:
```
/usr/bin/ls /foo/bar/
echo $?
```
Results will be an error of `No such file or directory` and exit status will be 2.

```
/usr/bin/ls /foo/bar/*
echo $?
```
Results will be a listing of the current working directory and exit status will be 0.
This task depends upon

Closed by  Eli Schwartz (eschwartz)
Thursday, 18 October 2018, 18:44 GMT
Reason for closing:  Not a bug
Additional comments about closing:  ls can't even do that, did you set nullglob in your shell?
Comment by Dave Reisner (falconindy) - Thursday, 18 October 2018, 18:42 GMT
Are you using bash? The logical explanation is that you've enabled nullglob in your shell.

$ ls /not/a/dir/*; echo $?
ls: cannot access '/not/a/dir/*': No such file or directory
2
$ shopt -s nullglob
$ ls /not/a/dir/*; echo $?
boot cache dev etc home lost+found mnt opt pkg proc root run srv sys systemd tmp usr var bin lib lib64 sbin
0

nullglob causes failed glob expansions to expand to nothing rather remaining as the pattern.

Loading...