Bug 1480672 - Inconsistent behaviour of -I switch with "ls"
Inconsistent behaviour of -I switch with "ls"
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash (Show other bugs)
x86_64 Linux
unspecified Severity unspecified
: rc
: ---
Assigned To: Siteshwar Vashisht
BaseOS QE - Apps
Depends On:
  Show dependency treegraph
Reported: 2017-08-11 13:07 EDT by roundsoftstudio
Modified: 2017-08-11 13:21 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2017-08-11 13:21:34 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Several commands with "ls -I" (92.90 KB, image/jpeg)
2017-08-11 13:07 EDT, roundsoftstudio
no flags Details

  None (edit)
Description roundsoftstudio 2017-08-11 13:07:54 EDT
Created attachment 1312196 [details]
Several commands with "ls -I"

Description of problem:
ls -I produces inconsistent outputs when the filter is not written with quotes

Version-Release number of selected component (if applicable):

How reproducible:
Very easy to reproduce

Steps to Reproduce:
1. Touch several files with several of them starting with the same pattern
   $ touch mybody
   $ touch thisisMY205
   $ touch thisisMYTRALALA
   $ touch THERING
   $ …

2. Write down some "ls -I" commands with wildcards
3. Conclude that ls -I malfunctions when the filter for excluding files matches at least 2 files.

Actual results:
   $ ls -I mybody*
   thisisMY205 thisisMYTRALALA THERING

   $ ls -I thisis*

   $ ls -I "thisis*"
   mybody THERING

Expected results:
  $ ls -I thisis*
  mybody THERING
Comment 2 Kamil Dudka 2017-08-11 13:21:34 EDT
If you do not quote the operand of -I, it is expanded by the shell before running the 'ls' command and only the first word produced by the expansion is used as the operand of -I.  The remaining words produced by the expansion are seen by 'ls' as the list of files to be listed.  You can consider using the -x option of bash to see the exact command being invoked.

This is just how bash (as well as any other POSIX-compatible shell) works.  Nothing to fix here...

Note You need to log in before you can comment on or make changes to this bug.