bug-findutils
[Top][All Lists]
Advanced

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

Re: [CLEAR] alias find issue


From: Dale R. Worley
Subject: Re: [CLEAR] alias find issue
Date: Wed, 07 Sep 2016 10:38:11 -0400

"Julien Rivoal" <address@hidden> writes:
> I have a question for an aliases utilization, I use since a long times this
> alias : alias ff='find . -name "\!*" -print'
>
> And now I can't use it and I don't understand why ?

I assume that the goal is to find all files whose names start with the
"!" character.

The critical problem is getting the correct argument values passed to
find by your shell.  In particular, the third argument must be the
string of two characters, "!*".

Handling this sort of situation is difficult because how the various
shells handle the "!" character varies in subtle ways, and sometimes is
altered by various shell options.

For instance, my shell has this rule:

       Enclosing  characters  in  double quotes preserves the literal value of
       all characters within the quotes, with the exception of $, `,  \,  and,
       when  history  expansion  is enabled, !.  The characters $ and ` retain
       their special meaning within double quotes.  The backslash retains  its
       special  meaning only when followed by one of the following characters:
       $, `, ", \, or <newline>.  A double quote may be quoted  within  double
       quotes by preceding it with a backslash.  If enabled, history expansion
       will be performed unless an !  appearing in double  quotes  is  escaped
       using a backslash.  The backslash preceding the !  is not removed.

Note the final sentence "The backslash preceding the ! is not removed."

I can verify this behavior by two methods:

    $ echo find . -name "\!*" -print
    find . -name \!* -print

    $ ( set -x ; find . -name "\!*" -print )
    + find . -name '\!*' -print

which show that the third argument to find is the three-character
string "\!*".

Indeed, with my shell, there is no way to use double-quotes to produce
an argument which is the desired string.  Possibilities that work are

    $ ( set -x ; find . -name '!*' -print )
    + find . -name '!*' -print
    $ ( set -x ; find . -name \!\* -print )
    + find . -name '!*' -print

Making this work in an alias is harder, but this seems to work for me:

    $ alias ff='find . -name \!\* -print'
    $ ( set -x ; ff )
    + find . -name '!*' -print

But the details of the solution will depend on your shell and what
settings you have active in your shell.

Dale



reply via email to

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