what are the differences between eval
and alias
commands?
Examples:
x=‘ls -d -l $HOME’
$x
eval $x
alias y=‘ls -l -d $HOME’
y
|
Mostly semantics. While combining your command strings into variables is useful for scripting purposes, it isn't good for aliasing. One visible reason is completion - while various completion scripts, like Second reason is Variables on the other hand may be useful for some uses that don't require mimicking binaries. A wide and good example is There might be some other things I'm not aware of, but the outcome is the same: those commands are to be used as they're intended. |
|||
|
Aliases are not to be used in scripts (disabled by default in non-interactive shells. You can even combine several aliases (like several strings for eval). But aliases don't give you the nice level of indirection which you get from the command line getting parsed twice:
I admit this could be done without eval ( shell-expand-line (M-C-e) works with neither without errors. :-) |
|||
|