i want to give alias

Hi all,
I m giving an alias to a command in bash shell under solaris o.s. As following.

alias "rm -r"="sh /dir1/move.sh"

It is throwing an error:

-bash: alias: `rm -r': invalid alias name

Please can anyone help me out for this.

Thank U
Naree

You need to create an alias for rm which parses its switches and breaks out to the real rm if it's not rm -r.

As an aside, functions are generally recommended over aliases.

Hi
I m not understanding ur reply. but even i have tired to alias rm. But when I tired to remove a directory rm -r it is not working.

This is tricky because you have to pass through to the "real" rm if it's not the -r option. Do you want to catch rm -r -i or -ri too, or just rm -r?

rm () {  # use a function instead of an alias
  case $1 in -r)  shift;  # get rid of the -r
      dir1/move.sh "$@";;
     *) /usr/bin/rm "$@" ;;
  esac
}

This is proof of concept only, because it only works when -r alone is exactly the first option.

Dear all,
I want to do for all -i -r -f etc. according i have done like this

MOVE.sh
---------
case $1 in
*) sh /dir1/move.sh
;;
esac

And i have created alias as following

alias rm="sh /dir1/MOVE.sh"

Even though it is not working. Please help me out for this issue.

Thank U
Naree

The whole case statement is redundant if you don't want any cases. You are not passing on the arguments to the function, that's the "$@" up there. But unless your move.sh already knows how to deal with -r, -i, -f, and other rm options, this is not the way to do it. If it does, good for you. But then you could simply have used alias rm=/dir1/MOVE.sh in the first place.