If you use double quotes when defining an alias, the parameter expansion occurs at the alias definition time.
$ echo $PWD
$ alias p="echo $PWD"
$ cd /
$ alias p
alias p='echo /tmp'
If you want the parameter expansion to occur at the time you call the alias, use single quotes when defining the alias:
$ alias p='echo $PWD'
$ cd /
Of course there is never any reason to run the command
. I know you used this just as an example, but since I have seen this so many times "in the wild" I'll clarify anyway: What this means is, run the
date command and capture the output (stripping off any trailing newlines). Then pass that captured output as an argument to the
echo command, which will print it, along with a single trailing newline. There is no advantage at all over just running
However, you are having a different problem here as well:
When you set the alias
d='$(date)', when you type
d you will get the literal result of typing
$(date) at the command line—the
date command will be executed, the output captured, the trailing newline will be stripped, and then the output will be parsed as a command by the shell (including word splitting and file glob expansion).
Since it's Friday, the first word output by
date is "Fri", so the shell tries to run this as a command.
If what you want is to see the date when you type
d, just use:
It doesn't matter which form you use, as there are no special characters requiring any form of quoting.