I've learned that filename expansions are done prior to command executions when running commands in Bash. But when trying the commands below (with -x option):
touch foo=3 # Create a file with name "foo=3"
+ touch foo=3
declare foo=?
+ declare 'foo=?'
alias foo=*
+ alias 'foo=*'
I don't get what I expect because foo=? and foo=* aren't expanded to the filename "foo=3":
declare -p | grep 'foo=' # => foo='?'
alias | grep 'foo=' # => alias foo='*'
But if I run another built-in like cd or a function accepting an assignment as a parameter written by myself like show_rhs() { echo "${1%=*}='${1#*=}'"; }
I gets what I expect (foo=? and foo=* are expanded).
cd foo=? # => foo=3: Not a directory
show_rhs() foo=* # => foo='3'
The only difference I can see here is declare and alias are built-ins AND accept an assignment as a parameter. It seems an pair of quotations is added to enclose the assignment before filename expansions according to the output of -x option.
But if the filename expansion does run before the command execution regardless of what the command is, the argument passed into declare and alias should be foo=3 rather than foo=? and foo=* due to the presence of the file "foo=3".
So does Bash do something special (maybe quoting wildcards?) to "a=b"-like arguments depending on commands before filename expansions?
(My environment: CentOS 5.8 64bit, GNU Bash 3.2.25)