So I am trying to understand the difference between two results in Bash to further my understanding of positional parameters:
$ find ./*.md
one.md
two.md
three.md
four.md
and:
$ ./findall.sh ./*.md
one.md
where findall.sh
is:
#!/usr/bin/env bash
find $1
In my understanding, these two should operations should be identical, but the use of positional parameters seems to return only one item. What am I not getting?
In both cases, your interactive bash is expanding
./*.md
before callingfind
. So your first command expands to this:In the second case, your command expands to this:
Then the script runs, and expands the command in the script to this:
Perhaps you meant to quote the wildcard:
But in either case,
find
will fail because the first arguments tofind
(before any arguments that start with-
) are the names of directories in which to search. There is no directory whose name is./*.md
, because/
cannot occur in a file or directory name.Perhaps you meant this, to find all files whose names match
*.md
, anywhere under the current directory:Perhaps you meant this, to find all files in the current directory (but not subdirectories) whose names match
*.md
: