The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
I want to know how we can give alias entry in cron naree SUN Solaris 1 03-12-2008 05:46 AM
Please give your inputs !!!! kpatel786 Shell Programming and Scripting 9 04-27-2007 07:59 AM
if i give this command what would be the value... suri Shell Programming and Scripting 1 03-05-2007 11:06 PM
Give us a hand RichardB UNIX for Dummies Questions & Answers 3 05-06-2002 08:37 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 74
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,084
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.
Reply With Quote
  #3 (permalink)  
Old 03-29-2008
Registered User
 

Join Date: Feb 2008
Posts: 74
Sir

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.
Reply With Quote
  #4 (permalink)  
Old 03-29-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,084
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?

Code:
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.
Reply With Quote
  #5 (permalink)  
Old 03-31-2008
Registered User
 

Join Date: Feb 2008
Posts: 74
I want to do for all

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
Reply With Quote
  #6 (permalink)  
Old 03-31-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,084
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.
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0