> I don't get this, after
> alias RM='mv $1 ~/garbage/'
> RM removeme
> I get an error:
> /bin/mv: cannot move directory onto non-directory: /home/trott/garbage/ ->
> removeme
With your alias, "RM removeme" expands to "mv $1 ~/garbage/ removeme",
which then becomes "mv /home/trott/garbage/ removeme" upon tilde
expansion and parameter expansion ($1 presumably never having been
set), and mv quite rightly gives you an error message.
Quote:> However,
> alias RM='echo $1'
> works:
It may seem to work, but not the way you apparently want it to:
$ alias RM='echo $1'
$ RM argument
argument
$ set another
$ RM argument
another argument
"$1" here refers to the shell's first positional parameter, not the
first argument of the alias-using command. An interactive shell usually
doesn't have any positional parameters. You can define them with the
set builtin command.
Quote:> So should or should not '$1' work in aliases?
Not for what you are trying to do. To do that with bash you need a
function:
function RM () { mv $1 ~/garbage/ ; }
(The word "function" is optional.) You can have aliases in csh or tcsh
do what you want, but the syntax is different, both for the alias and
for the way of referring to arguments.
--
John Wingate Language serves three functions. One is to
the third is to conceal the absence of ideas.
--Otto Jespersen