Reputation: 9
i want find some files with given arguments in command line, this is my script
find -name $1
when i run this with argument '*.txt'
it doesn't work. Why? What I can fix it?
Upvotes: 0
Views: 185
Reputation: 295687
An unquoted expansion of a wildcard is replaced with a list of filenames in the current directory that match the pattern.
Thus:
set -- '*.txt' # same as running your script with '*.txt' as first argument
touch a.txt b.txt c.txt
find -name $1
...will run:
find -name a.txt b.txt c.txt
...which isn't valid usage.
To avoid glob expansion, always quote your expansions: find . -name "$1"
Upvotes: 2