From unknown Tue Aug 19 07:26:44 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#33942 <33942@debbugs.gnu.org> To: bug#33942 <33942@debbugs.gnu.org> Subject: Status: ls directly uses filename as option parameter Reply-To: bug#33942 <33942@debbugs.gnu.org> Date: Tue, 19 Aug 2025 14:26:44 +0000 retitle 33942 ls directly uses filename as option parameter reassign 33942 coreutils submitter 33942 westlake severity 33942 normal tag 33942 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 01 03:07:08 2019 Received: (at submit) by debbugs.gnu.org; 1 Jan 2019 08:07:08 +0000 Received: from localhost ([127.0.0.1]:43769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1geF4t-0001nQ-P7 for submit@debbugs.gnu.org; Tue, 01 Jan 2019 03:07:08 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50535) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1geAAY-0002Oo-H1 for submit@debbugs.gnu.org; Mon, 31 Dec 2018 21:52:38 -0500 Received: from listsout.gnu.org ([209.51.188.17]:42134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1geAAY-0002V6-1J for submit@debbugs.gnu.org; Mon, 31 Dec 2018 21:52:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1geAAW-0006Tl-Lz for bug-coreutils@gnu.org; Mon, 31 Dec 2018 21:52:37 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_LOW autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1geAAT-0002Ku-FK for bug-coreutils@gnu.org; Mon, 31 Dec 2018 21:52:36 -0500 Received: from alt23.smtp-out.videotron.ca ([70.80.0.74]:60754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1geAAT-0002Gk-86 for bug-coreutils@gnu.org; Mon, 31 Dec 2018 21:52:33 -0500 Received: from [192.168.1.145] ([24.202.243.79]) by Videotron with SMTP id eAAOgx1qd6r0CeAARgzeNQ; Mon, 31 Dec 2018 21:52:31 -0500 X-Authority-Analysis: v=2.3 cv=D61p1MZj c=1 sm=1 tr=0 a=bLM/ODb0GI2A3veO+gxPdQ==:117 a=bLM/ODb0GI2A3veO+gxPdQ==:17 a=IkcTkHD0fZMA:10 a=Phi_U4S7heDcwIXf1C0A:9 a=QEXdDO2ut3YA:10 To: bug-coreutils@gnu.org From: westlake Subject: ls directly uses filename as option parameter Message-ID: <4b1f99bd-6c68-5adc-c258-3a6f7d8530e8@videotron.ca> Date: Mon, 31 Dec 2018 21:52:28 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfCCKTYGHjaK5nf8EohXvs2lRXunFOnKqdjoZbihj6rLpEaShhHZgL7FgZE0pWnXfS//LwhD7DbpW4w4wV3i8oyKd+K/HRCJAePz4R/sGBrdr/MhqGKQa S6uut4Je19R11bkZgOC4n6OJHhhzuePRhHtt5R0/xyaq3p0mGZDn3yt++n1yKhOMwy3MosFtpxCuvQ== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.80.0.74 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 01 Jan 2019 03:07:06 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hi coreutils team, I have known long time about certain commands that use "--" as a specially reserved parameter. However, I find the behaviour of it with ls showing a little confusing results and believe this surmounts to a bug, by example, ls exhibits unpredictable behaviour when there's also a file called "--". it took me a bit of time today to look into after I revisited the problems of having "-" at the beginning of filenames, but decided with a little extra time into the holidays to look at it.. and found out that having a file called "./--" creates unpredictable behaviour.. cut to the chase, I pretty much summarize that the filename "./--" is definitely being consumed and utilized as a "program parameter" which is not a very sane thing for a program to do (so this is why I am filing this as a bug report here first rather than going directly with developers responsible for getopt) $ mkdir tmp $ cd tmp (so we start with an empty folder) $touch 0 ./--a ./-a ./-_a ./-- $ ls -lad -* [^-]* -rw-r--r-- 1 user user 0 Dec 31 18:37 0 -rw-r--r-- 1 user user 0 Dec 31 18:33 -_a -rw-r--r-- 1 user user 0 Dec 31 18:34 --a ls -lad -* [^-]* -rw-r--r-- 1 user user 0 Dec 31 18:37 0 -rw-r--r-- 1 user user 0 Dec 31 18:33 -_a -rw-r--r-- 1 user user 0 Dec 31 18:34 --a $ ls -lad -- -* [^-]* -rw-r--r-- 1 user user 0 Dec 31 19:10 -- -rw-r--r-- 1 user user 0 Dec 31 18:37 0 -rw-r--r-- 1 user user 0 Dec 31 18:33 -_a -rw-r--r-- 1 user user 0 Dec 31 18:34 --a $ ls -lad -- * -rw-r--r-- 1 user user 0 Dec 31 18:35 -- -rw-r--r-- 1 user user 0 Dec 31 18:37 0 -rw-r--r-- 1 user user 0 Dec 31 18:33 -_a -rw-r--r-- 1 user user 0 Dec 31 18:34 --a Notice that example 2, "-*" is being parsed with "--a" , is "./--" not showing up due to "design" or is this a "bug" ? If "--a" is getting listed, then so should the file called "./--", "$ ls -lad -- *" this command shows all files. Delete file ./-- with "rm ./--", and now we try the command "ls -lad *", the output now is ls complains. Okay I understand ls complaining: " ls -lad * ls: invalid option -- '_' Try 'ls --help' for more information. " ^ but it is counter-intuitive because having a file called "./--", and this command passes. If there is detectable filenames as the next example would show, then why can't "-*" list file ./-- ? Is this a bug or a design to comply with similar behaviour of ls on *nix? See this example, " ls -lAd -- -* [^-]* -- " Here the first instance of "--" is taken as a special option for ls, and the second "--" is being taken as a filename literal. There is really only one file called ./-- , but here as expected it is intentionally being listed twice. So here ls works as expected, but why I am mentioning this.. " $ ls -* [^-]* -- -lad ls: cannot access '-lad': No such file or directory -- 0 -_a --a " Here we can see that ls is performing filenaming parsing after it detected filenaming arguments after the "-*" , evidently it is also taking "-lad" as a filename literal, and this is understood. So essentially here we have "--" being taken as a filename literal, and ls uses this correctly. Question: so why can't ls expand "-*" to "./--" ? (fwiw, it does when using "ls -lad -- -*, and when using "--" as a special parameter) What about file "---" or file "----" ? These files show up properly, $ touch ./--- ./---- $ ls -lAd -* [^-]* -rw-r--r-- 1 user user 0 Dec 31 21:10 --- -rw-r--r-- 1 user user 0 Dec 31 21:10 ---- -rw-r--r-- 1 user user 0 Dec 31 21:02 0 -rw-r--r-- 1 user user 0 Dec 31 21:02 -a -rw-r--r-- 1 user user 0 Dec 31 21:02 -_a -rw-r--r-- 1 user user 0 Dec 31 21:02 --a ^ file "./--" is missing, why? (getopt?) I'm curious as to why ls would take the file "./--" and then use that as a "special parameter" rather than a regular file, and then on top of this completely omit it from output ( ls -lad * )... It uses it as a special parameter because it then does not fail with that message " ls: invalid option -- '_' " ... I think it is a bug, because if something is read from disk, it should not directly be treated as a special parameter to ls, .. so this is why I am filing this. thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 02 04:21:34 2019 Received: (at 33942) by debbugs.gnu.org; 2 Jan 2019 09:21:34 +0000 Received: from localhost ([127.0.0.1]:44298 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1geciU-0000dK-4D for submit@debbugs.gnu.org; Wed, 02 Jan 2019 04:21:34 -0500 Received: from mail-pg1-f173.google.com ([209.85.215.173]:45288) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1geciR-0000cz-K1; Wed, 02 Jan 2019 04:21:32 -0500 Received: by mail-pg1-f173.google.com with SMTP id y4so14355182pgc.12; Wed, 02 Jan 2019 01:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=qQr+zr7VkfJdO5tYDSAKfdBFgPiOuaI6RmhX9bXiOoI=; b=mR8KlI1w9y7q/cxtIIwCnPNCVo+EORd5r+DSJD6+nqdIhbVp97YAYzW1xXx7QrUyLu GsLDjSu8fjqEHQC2SgucenrZyxzj6Q2cdySYnhXOVLx9ZblG7l1fFFW6GpD4nLnHry1T xcm1aWy54Mb1QHV9LETYdrCzMXreWSJLN4+JSE1oUbRCws9LF0nKRsfNShaK8EJvja7E RlsXFIsbhUiGPD8DCUfY8mLmmYpwdgyv70qD0hT24zEKL1Dc1/3yMkqJT7AMis5wYCmr iBBNFiT1czG9LEVJKfbO2A1Z1uKcEDHCmJTAoHFw9O8gVZ6pIswXC9UdCJtKMkNQrnoo 9fwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qQr+zr7VkfJdO5tYDSAKfdBFgPiOuaI6RmhX9bXiOoI=; b=bJ/HcT3yCNA70C5IhjJwWR/UVSPTvEJ7DWQMuWMkiZRbx6J1miyKATNb6Bi6Vlwnff dENNsnFtErPrH4vjj6znceCAIqK6uLUD9YCH+gliA0iZkED5xV1z0EyOnVyoVIuxQavi sPEPkLdjGWfR8DKtpmVm5xRtU94Ecez91DdeoSD4HYt5EEO21Hcd/VeczisdrFZYMuCb ui+C312gkf2PtwsZMvqhhDFDXFMqQJjLSvHvqMt/XjWJT0IRZMZ69KpR1YvQagarJ/WN kGDM/c+9eAIVZA7wStIARbAxiLviKo/3BXAFUAWufPGB+jebeF0S51MOh8nFaoRSiaqz upuQ== X-Gm-Message-State: AJcUuke7US7pPATDHkXtf0lywKBEhGmjYxbJf7mNFxXzez7xFxofm6HR W8+/WmcdU+PyNG7b+fWsCCUHMYVX X-Google-Smtp-Source: ALg8bN7OJBgQ82EOiIlfGna90IiZfwuixYNQwOwEjdI4CsmdFLcRdnafRSToMOtXzsun1uk3BxmdfA== X-Received: by 2002:a63:94:: with SMTP id 142mr40165558pga.74.1546420885252; Wed, 02 Jan 2019 01:21:25 -0800 (PST) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id k38sm106211165pgb.33.2019.01.02.01.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 01:21:24 -0800 (PST) Subject: Re: bug#33942: ls directly uses filename as option parameter To: westlake , 33942@debbugs.gnu.org References: <4b1f99bd-6c68-5adc-c258-3a6f7d8530e8@videotron.ca> From: Assaf Gordon Message-ID: Date: Wed, 2 Jan 2019 02:21:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <4b1f99bd-6c68-5adc-c258-3a6f7d8530e8@videotron.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 33942 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 33942 notabug close 33942 stop Hello, On 2018-12-31 7:52 p.m., westlake wrote: >  I have known long time about certain commands that use "--" as a > specially reserved parameter. However, I find the behaviour of it with > ls showing a little confusing results and believe this surmounts to a bug, What you describe below is not a bug, but the indented behavior. >[...] and found out that > having a file called "./--" creates unpredictable behaviour [...] First, It's important to understand the filename is not "./--" (4 characters), but "--" (2 characters) in the current directory ("./"). This is similar to typing "/home/user/--". You wouldn't say the filename is "/home/user/--" - the filename is "--" and it is in the directory "/home/user/". While it might sound like splitting hairs, this is critical to understand what's going on here. The filename starts with (and contains only) two minus characters. > $ touch 0 ./--a ./-a ./-_a ./-- > > $ ls -lad  -* [^-]* Second, It is important to understand that it is the shell which does the filename completion (e.g. "*" and "-*" etc.). The filename expiation happens before "ls" is even executed. With this in mind, it'll be easier to understand what's going on if you add "echo" to every command, and look at what's printed: $ echo ls -lad -* [^-]* ls -lad -- -a -_a --a 0 $ echo ls -lad -- -* [^-]* ls -lad -- -- -a -_a --a 0 $ echo ls -lad -- * ls -lad -- -- 0 -a -_a --a > Notice that example 2, "-*" is being parsed with "--a" ,   is "./--" not > showing up due to "design" or is this a "bug" ?  If "--a" is getting > listed, then so should the file called "./--", Not a bug. Using "echo", you can see what are the exact parameters that are passed to "ls". And then follow these simple steps: 1. The first "--" tells ls to stop processing options. 2. anything that starts with a dash BEFORE the first "--" marker is taken to be an option. 3. anything AFTER the first "--" marker is taken to be a file name (strings starting with a single dash, and including additional "--" strings). That's it - and it works consistently for most GNU programs, not just ls. > Okay I understand ls complaining: > " > ls -lad * > ls: invalid option -- '_' > Try 'ls --help' for more information. using "echo" will show what's happening: $ rm ./-- $ echo ls -lad * ls -lad 0 -a -_a --a With the file "--" gone (which was seen be "ls" as the "--" marker), ls now sees "-a" as an option (a valid option), then it sees "-_a" (and "_" is not a valid option) - hence the error message. > ^ but it is counter-intuitive because having a file called "./--", and > this command passes. > If you follow the simple steps above (and use "echo" to see how the shell performs filename expansion), I hope all the other issues you've listed in your email will become clear. If not - please do write with specific cases. I'm closing this as "not a bug", but discussion can continue by replying to this thread. -assaf From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 02 13:09:55 2019 Received: (at control) by debbugs.gnu.org; 2 Jan 2019 18:09:55 +0000 Received: from localhost ([127.0.0.1]:44957 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gekxn-000538-16 for submit@debbugs.gnu.org; Wed, 02 Jan 2019 13:09:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gekxl-00052z-Px for control@debbugs.gnu.org; Wed, 02 Jan 2019 13:09:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gekxl-00070x-3Z for control@debbugs.gnu.org; Wed, 02 Jan 2019 13:09:53 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gekxk-00070l-Tv for control@debbugs.gnu.org; Wed, 02 Jan 2019 13:09:53 -0500 Received: from rgm by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1gekxj-00068M-Fg for control@debbugs.gnu.org; Wed, 02 Jan 2019 13:09:52 -0500 Subject: control message for bug 33943 To: X-Mailer: mail (GNU Mailutils 2.99.98) Message-Id: From: Glenn Morris Date: Wed, 02 Jan 2019 13:09:51 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) forcemerge 33942 33943 From unknown Tue Aug 19 07:26:44 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 31 Jan 2019 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator