To be completely clear, an alias is a simple
command name substitution. If the first word of the line you run matches a defined alias, then it's replaced with the contents of the alias and the modified command line is executed.
Code:
$ alias echoit='echo foo'
$ echoit bar
foo bar
The command actually executed is "
echo foo bar". "echoit" has been replaced with "echo foo".
In short, you can't build arbitrary commands with aliases, you can only use them to replace the first word with a different string. The rest of the contents of the line remain where they started.
Note that there are tricks you can use to do some really clever things with aliases, but it's generally not recommended to do so. aliases were really designed to be simple command shortcuts. Use functions for more complex stuff.
BTW, colucix's explanation is not
quite right in one respect. Variable substitutions are still made. If the parent shell just happens to have a $1 value set, then it will show up in the final command.
Code:
$ alias echoit='echo $1'
$ echoit bar
bar #no output from $1
$ set -- foo #set the first positional parameter in the shell
$ echoit bar
foo bar #now we get output.
But note that this
$1 is the
running shell's parameter, already sitting in the environment, and has nothing really to do with the contents of the command or the alias itself. The line as executed is still simply "
echo $1 bar", with $1 being substituted before execution.