Quote:
Originally Posted by
COKEDUDE
Does shell expansion get handled differently in find with double quotes and single quotes than other programs? I know in grep shell expansion still happens with double quotes and not with with single quotes. I learned that from fpmurphy.
You need to understand that the shell's behavior is invariant with regard to what utilities you intend to invoke. The shell does not care one bit if you are trying to use find, or grep, or ls, or... The shell's job is basically to read a line of text, process that text according to its rules (expansions, substitutions, redirections, et al), and create a process running the desired utility with the requested arguments.
The invoked utility does not know or care if it was created by a command interpreting shell. It simply processes the arguments it was passed and gets to work.
Not knowing where the shell ends and a utility it invokes begins is a huge impediment to understanding what's going on. If this line is not clear to you, in my opinion, the most beneficial thing you could do in the very near future is to spend a few hours with the command parsing section of your shell man page, until you understand it thoroughly. It will serve you very, very well. Once you get it, you can look at the most complicated stuff and work your way through it.
You'll learn the order in which the shell performs substitutions and expansions. It'll also become trivial to understand the effects of quoting. In short, any text enclosed by single quotes (aka strong quotes) is taken literally. Nothing special happens. Double quotes (aka weak quotes) bypasses only those shell expansions, substitutions, and parsing steps that could increase the number of fields (this includes field splitting on IFS characters and filename expansion). So, no matter how the text within the double quotes is modified by processing, in the end you'll always have a single field (this is why double quoted command substitutions in a for loop list are utterly pointless).
Note: There is one exception to the double quote rule: "$@" expands to multiple fields, one per positional parameter (a hack workaround to allow dealing with a list of items when there was no list type).
Also, it may help to understand the basics of the system's execve(2) system call, which is responsible for loading a new executable image, which includes passing the command line arguments and the environment.
Regards,
Alister