putting find in a bash_profile function
-
01-07-2021 - |
문제
I want to make bash function in my .bash_profile that basically does a find ./ -name $1
, very simple idea, seems not to work. My tries don't print things the right way i.e.:
find_alias() {
`find ./ -name $1 -print`
}
alias ff='find_alias $1'
The above if I do something like ff *.xml
I get the following one liner:
bash: .pom.xml: Permission denied
The following after that:
find_alias() {
echo -e `find ./ -name $1 -print`
}
alias ff='find_alias $1'
does find them all, but puts the output of that onto one massive long line, what am I doing wrong here?
해결책
find_alias() {
find ./ -name $1 -print
}
You don't need, nor want, the backticks. That would try to execute what the find
command returns.
다른 팁
Backticks make shell treat output of what's inside them as command that should be executed. If you tried ´echo "ls"´
then it would first execute echo "ls"
, take the output which is text ls
and then execute it listing all files.
In your case you are executing textual result of find ./ -name *.xml -print
which is a list of matched files. Of course it has no sense because matched file names (in most cases) are not commands.
The output you are getting means two things:
- you tried to execute script from pom.xml (like if you typed
./pom.xml
) - makes no sense - you don't have execution rights for that file
So the simple solution for you problem, as @Mat suggested, is to remove backticks and let the output of find
be displayed in your terminal.