supergra has answered the primary point, but it may leave you wondering why you see your text echoed back to you even though the variable was not set. That is, you have echo $x
at the end of your alias, and indeed you see no
when you enter oh no
, but that does not mean that echo is echoing the variable.
What is happening there is that echo
is printing the (empty) variable, but then echo
is also catching the "no" part separately. If you do alias tmp 'echo $1'
and try tmp hi
you will print "hi" because it's as if you did "echo $1 hi".
To see this more clearly, try alias tmp 'echo abc $1 def '
and do tmp hi
again, and you will print "abc def hi". Again, if you try alias tmp 'echo $1 & which '
and use it again you should, unless you have a command named hi
, see something like "hi: Command not found." or if you do tmp ls
you will see the output of which ls
.
One more example: try alias tmp 'echo $1 & '
and tmp hi
to see that it actually tries to execute hi
as if it were a command, which can be dangerous if you were not expecting that.