hput <
[email protected]>:
Running: Ubuntu 20.04 linux with bash
Some how I've managed to get a directory written with the name
`--head--'. Haven't been able to figure out how this got written.
[…]
I want to see it with a simple `ls' or `ls -l' command. A few of
what I've tried:
are:
ls
'--head--'
\-\-head\-\-
[\-][\-]head[\-][\-]
[…]
As Janis already pointed out, "ls" and most of the standard
utilities parse their argument list in the following manner: They
look at each of its arguments, starting with the left most and
proceeding to the right: If the argument starts with (at least) one
"-" then they consider it to be an option except when they are told
(see below) to not consider the remaining arguments as options.
In your use case "ls" would consider "--head--" as a (GNU long)
option. In the case of a filename starting with a "-" that's a
problem (as you encountered).
But there is a remedy: the special option "--". It tells the
utility, that all following arguments are not to be interpreted as
options, even if they look like an option, i. e. if they start with
a "-".
So the solution would be: Before any non‐option arguments that you
supply to "ls" always put that special end‐of‐options‐option "--" into the argument list:
ls -- the filenames you want to specify …
or
ls -l -- the filenames you want to specify …
This end‐of‐options‐option doesn't do any harm should it be not necessary, but it helps avoiding such surprises.
It's become a habit of mine to always supply an
end‐of‐options‐option no matter whether I think it's necessary or
not.
For example, the command
ls -d [![:letter:]]*
will show all filenames in the current directory that don't start
with a letter or a ".". If there happens to be a filename like
"--head--" it will be put into the argument list and interpreted as
an option. Note: If one looks at that command one might not know
whether in the current directory there happens to be a filename
"--head--". That's why I wrote "no matter whether I /think/ it's
necessary or not".
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)