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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to create an ALIAS.... mac4rfree Shell Programming and Scripting 2 04-01-2009 12:05 AM
How to create alias for a function neeto UNIX for Dummies Questions & Answers 2 11-05-2008 12:48 PM
How to create alias with awk command papa1980 UNIX for Dummies Questions & Answers 5 06-24-2008 12:18 AM
I want to create a command alias cstovall UNIX for Dummies Questions & Answers 2 12-03-2002 10:20 AM
Create an alias mozark High Level Programming 1 10-08-2002 10:17 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
glamo_2312 glamo_2312 is offline
Registered User
  
 

Join Date: Sep 2008
Location: INDIA
Posts: 19
Question How to create multiple word alias

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.

  #2 (permalink)  
Old 05-27-2009
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 429
you already have an alias for rm, so using rm -rf resluts in executing

$HOME/script -rf

so there is no need to specify arguments, and afaik it's not possible
  #3 (permalink)  
Old 05-27-2009
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,311
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
}
Sponsored Links
Reply

Bookmarks

Tags
alias, rm, rm -rf, script, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0