The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-27-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by glamo_2312 View Post
Hi,

I have created a script which will move the file passed as $1 to a particular folder.

In the .profile of my unix user i have created an alias as

alias rm="$HOME/script"

Now i want that to do

alias rm="$HOME/script"

alias \rm="$HOME/script"

alias \rm -rf ="$HOME/script"

alias rm -rf ="$HOME/script"


It does not take rm -rf as ab alias.
How to do this.

Use functions, not aliases.

Code:
unalias rm
rm()
{
  if [ "$1" = "-rf" ]
  then
    shift
    $HOME/script "$@"
  else
    command rm "$@"
  fi
}