alias RM='mv $1 ~/garbage/'

alias RM='mv $1 ~/garbage/'

Post by wroo » Mon, 02 Jul 2001 11:50:25



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

(~/garbage/ is a directory, and ./removeme is a file)

However,
alias RM='echo $1'
RM argument
works:
argument

So should or should not '$1' work in aliases?

Wroot

 
 
 

alias RM='mv $1 ~/garbage/'

Post by John Wingat » Mon, 02 Jul 2001 13:35:10



> 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

 
 
 

alias RM='mv $1 ~/garbage/'

Post by Doppler Do » Tue, 17 Jul 2001 13:41:05



> 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

> (~/garbage/ is a directory, and ./removeme is a file)

> However,
> alias RM='echo $1'
> RM argument
> works:
> argument

> So should or should not '$1' work in aliases?

> Wroot

If you're using bash, $1 will not work.  See the man page:

       There is no mechanism for using arguments in the  replace-
       ment  text,  as  in csh.  If arguments are needed, a shell
       function should be used.

So really, what the alias is doing is in fact getting the shell
to do "mv ~/garbage/ removeme" - not what you want!

--
Remove the knickers from my email to reply.

 
 
 

alias RM='mv $1 ~/garbage/'

Post by chri » Wed, 18 Jul 2001 03:42:16




>> 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

>> (~/garbage/ is a directory, and ./removeme is a file)

>> However,
>> alias RM='echo $1'
>> RM argument
>> works:
>> argument

>> So should or should not '$1' work in aliases?

>> Wroot

> If you're using bash, $1 will not work.  See the man page:

>        There is no mechanism for using arguments in the  replace-
>        ment  text,  as  in csh.  If arguments are needed, a shell
>        function should be used.

> So really, what the alias is doing is in fact getting the shell
> to do "mv ~/garbage/ removeme" - not what you want!

Also, If Im not mistaken the double quotes would be needed in order for the
variable to interpolate ,
 
 
 

1. Can't get '$1' to work in a .profile alias

Help..
I have an alias set up in my .profile to run a unix script.
I'd like to be able to 'pass' diffent values to the script.

I'm using /bin/sh

Here is the alias in my .profile
alias mycheck="/apps/scripts/file_check fred.txt"

I'd like to be able to pass other values to file_check besides
'fred.txt'.

I've tried  
alias mycheck="/apps/scripts/file_check $1"
but when I run the 'alias' the value passed to file_check is 'vi', I
also tired $2 and the value passed was '-o'.

My confusion... This one works just fine..
alias mytest="ll \$1"

Thanks,
Glenn

2. basic

3. alias rm='mv $@ /trash' ???

4. NEC CDR 84J Not Recognized on Bootup

5. kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

6. Non-*nix OS built on linux kernel?

7. Q: alias psef='ps -ef $1'

8. Can't setup sound card after upgrade from 2.2.5 to 2.3.17?

9. expect script doesn't understand '$1' from command line?

10. How expand the variable inside '$1'?

11. ps -eo pid,args | awk ' /[b]lah/ { print $1 } ' | xargs kill

12. '-i' option for 'cp' and 'mv'

13. Can't get ls mv rm to behave with zlibc