[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [CLEAR] alias find issue
From: |
Stephane Chazelas |
Subject: |
Re: [CLEAR] alias find issue |
Date: |
Wed, 7 Sep 2016 14:47:23 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2016-09-06 15:39:47 +0200, Julien Rivoal:
[...]
> I have a question for an aliases utilization, I use since a long times this
> alias : alias ff='find . -name "\!*" -print'
[...]
You're confusing csh with sh.
alias ff 'find . -name "\!*" -print'
Is a csh dirty hark using history expansion to have a sort of
parameterized alias.
Note that it's not really "parameters" but in effect the words
after the alias being shoved back inside those "..." and parsed
again by the shell.
What that means is that for instance, if you do:
ff '`reboot`'
That will call "reboot" even though that `reboot` was quoted.
Because that ends up parsing:
find . -name "'`reboot`'" -print
Same for
ff ";reboot;echo"
Which becomes
find . -name "";reboot;echo"" -print
POSIX shells (like bash, the ones that use the "alias a=b"
syntax instead of "alias a b") have functions so don't need to
resort to such dirty hacks.
ff() {
find . -name "$*" -print
}
Would define a function that passes the concatenation of its
arguments (with the first character of $IFS, space by default)
to find's -name.
Now, where with the (t)csh alias
ff *.txt
would call
find . -name "*.txt" -print
With POSIX shells, you'd need to quote that *.txt so it be
passed verbatim to ff:
ff '*.txt'
Otherwise, if there are txt files in the current directory, the
*.txt would be expanded to the shell and the find command would
become something like:
find . -name 'foo.txt bar.txt' -print
With zsh, you can make it:
ff() {
find . -name "$*" -print
}
alias ff='noglob ff'
For globbing to be disabled for the ff command (here implemented
as a function).
--
Stephane