Bug 1480672

Summary: Inconsistent behaviour of -I switch with "ls"
Product: Red Hat Enterprise Linux 6 Reporter: roundsoftstudio
Component: bashAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.10CC: kdudka
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-11 17:21:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Several commands with "ls -I" none

Description roundsoftstudio 2017-08-11 17:07:54 UTC
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):
6.something

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*
   thisisMYTRALALA

   $ ls -I "thisis*"
   mybody THERING


Expected results:
  $ ls -I thisis*
  mybody THERING

Comment 2 Kamil Dudka 2017-08-11 17:21:34 UTC
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...