I think you're mixing up your shell expansions, specifically ${ }
and $( )
. They look similar, but do completely different things, and it's important to use the right one for the job. $( )
does command substitution -- it runs what's inside the $( )
as a shell command, captures its output, and basically inserts it into the command line at that point. ${ }
, on the other hand, treats what's inside it as a variable or parameter name (maybe with some modifiers attached), and inserts its value.
So when you use "$(directory)"
, the shell tries to run directory
as a command. But it's not a command, it's a variable, so that fails and you get a "command not found" error. You want "${directory}"
(or just "$directory"
, since this is one of the simple cases where `{} is optional).
Also, in the line
echo "(basename "${file}")"
...there's no $
before (basename
, so it's not treated as any sort of expansion, just a plain string. You want "$(basename...)"
, except that (as UnrealApex pointed out) the echo
and the "$( )"
are basically cancelling each other out, and you should just omit both. So just use:
basename "${file}"
One more recommendation: the function
keyword is nonstandard and unnecessary. I recommend just starting function declarations like this:
myfind() {
...