"Variables are much more universal than aliases" - not entirely true!
To execute commands, variables have some restrictions that are not shared by aliases.
Try using a variable to define a command that echoes a single asterisk on the command line:
$ myCommand="echo *" $ $myCommand file1.x file2.y file3.z
Extending * is not what you wanted, so try the following:
$ myCommand="echo \"*\"" $ $myCommand "*"
But now you have extra quotation marks β you didn't want that either!
But this works fine:
$ echo "*" *
So:
$ alias myCommand="echo \"*\"" $ myCommand *
This is because the quotes inside the variable are treated as alphabetic rather than syntactic when the variable is expanded - therefore, in this case they become part of the parameter that is passed to the echo command, while the βas isβ command is executed with the alias and the quotes are considered as syntactic and are analyzed before the echo is called, just like when you enter the same command directly from the command line.
Dan king
source share