coreutils
[Top][All Lists]
Advanced

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

Re: test: hidden files


From: Pádraig Brady
Subject: Re: test: hidden files
Date: Sun, 13 Aug 2017 01:30:16 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

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]