Issue
When I execute ls --
:
$ls --
a.out ft_ls.c ft_ls.h ft_ls.h.gch libft`
it display the content of the current directory,
but the -
alone is interpreted like a directory named '-':
$ls -
ls: -: No such file or directory
and ls ---
is illegal flag:
$ls ---
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
and can I know why ---
isn't interpreted by default as a file name?
Solution
--
has a special meaning as the marker of "end of options"; whereas ---
or -
has no such special meaning.
POSIX convention says:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
If you are implementing ls
then you might be interested in using getopt
function and you can easily implement similar option processing as the ls
command.
Answered By - P.P