coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test: hidden files


From: Marton Kun-Szabo
Subject: Re: test: hidden files
Date: Mon, 14 Aug 2017 00:22:05 -0700

Ok, thanks, I won't bother then.
I didn't get the 'ls' example though; AFAIK 'ls -a' prints everything and
'ls' only prints those files whose name don't start with a dot.
I presume '.' and '..' are named deliberately, in order not to interfere
with programs that are supposed to recursively iterate through the
filesystem starting from a given directory level.

Thanks,
Marton


On Aug 13, 2017 01:30, "Pádraig Brady" <address@hidden> wrote:

On 10/08/17 15:55, Marton Kun-Szabo wrote:
> Dear coreutils-dev,
>
> I'd like to add a new feature to "test" that checks whether a file exists
> and is hidden (the first character of the filename is a dot). I think this
> is a useful and universal feature that is currently missing from "test"
and
> is not on the list of rejected features yet.
> The "-H' argument is currently unused, the main modification would look
> like this:
>
> src/test.c
>
> +    case 'H':           /* File is hidden? */
> +      unary_advance ();
> +      return (stat (argv[pos - 1], &stat_buf) == 0
> +              && (argv[pos - 1][0] == '.'));
> +
>
> I would be happy to implement this feature along with all the necessary
> documentation (both in coreutils.texi and in the "--help" section) and
> submit a patch when everything is done.
>
> Questions:
>  1) Is this a useful feature? Or would it end up on the list of rejected
> features?
>  2) Any planned other use of the "H" argument in the future?
>  3) Any comments on the above implementation?

Did you know that .blah corresponding to hidden files
was a bug in the initial implementations of ls(1) :)
I.E. the code wanted to skip '.' and '..', so did the equivalent of
  if (filename[0] == '.') continue;

Anyway...
I'm not sure about this since it's so easy to achieve in portable shell.
For example:

  startswith() { [ "${2#$1}" != "$2" ]; }

  file='.blah'

  startswith . "$file" && test -e "$file"

cheers,
Pádraig


reply via email to

[Prev in Thread] Current Thread [Next in Thread]