Why does variable expansion within an alias work “as intended” in only one of these cases?
问题 This question was inspired in part by this one. alias foo='ls -1 $1' foo /etc displays the contents of /etc, one item per line. ls -1 /etc | tail displays the last ten items in /etc. But alias foo='ls -1 $1 | tail' foo /etc displays: tail: error reading `/etc': Is a directory 回答1: I have found variable expansion in aliases to be flaky, and not recommended: http://www.gnu.org/software/bash/manual/bashref.html#Aliases Use a function instead: function foo() { ls -1 $1; } 回答2: Aliases done this