I frequently run this command:
eval $(resize)
In order not to have to write it every time I have added this line to $HOME/.alias
alias r="eval $(resize)"
But when I run r
it sets me to 80 columns, not what it corresponds to. If the alias is ready, this appears:
~> alias | grep "alias r="
alias r='eval COLUMNS=80;
That is, $(resize)
it is evaluated when the .alias file is loaded but I want it to be evaluated when I execute r
.
Commands that are written inside double quotes are executed automatically. Therefore, when you say
alias r="eval $(resize)"
this command, it is interpreted andr
its expansion becomes valid.To make it run every time, just use single quotes:
Let's see an example with a command whose output changes as
date
. We define the alias and call it three times, once every second:I generate aliases with single quotes:
We see that the result changes each time:
With double quotes:
We see that the result is always the same:
Let's look at another simpler case with quotes, where we define a text that contains a variable.
With single quotes,
$v
it is not interpreted:With the double quotes, yes: