i want to give alias


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting i want to give alias
# 1  
Old 03-29-2008
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
# 2  
Old 03-29-2008
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.
# 3  
Old 03-29-2008
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.
# 4  
Old 03-29-2008
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.
# 5  
Old 03-31-2008
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
# 6  
Old 03-31-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

2. UNIX for Advanced & Expert Users

About to give up on XEmacs 21.5.29

Folks, I am hoping someone out there can help me. I have been writing code for in-excess of 10 years. Throughout all this time I have used Xemacs. I have picked up bits of customizations here and there over the years, but would not profess to be anything of an expert in Lisp (or have a heavily... (3 Replies)
Discussion started by: petermc
3 Replies

3. Solaris

I want to know how we can give alias entry in cron

Hi all I have created an alias for a running a script called script.sh as alias utils="sh ~/script.sh". Moreover i m using bash shell, even i have given the entry for alias in .profile in my home directory.I have given alias entry in crontab file as 30 12 * * * utils ... (1 Reply)
Discussion started by: naree
1 Replies

4. Shell Programming and Scripting

Please give your inputs !!!!

I am trying to extract two fields from the output of ifconfig command on one of my sun server . The output looks like : root@e08k18:/tmp/test# ifconfig -a lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 ce0:... (9 Replies)
Discussion started by: kpatel786
9 Replies

5. Shell Programming and Scripting

if i give this command what would be the value...

if i give dir=/tmp/${0##*/} what would b the value stored in dir ..i'm more concerned about the 0##*/ part.. (1 Reply)
Discussion started by: suri
1 Replies

6. Programming

Pls give me some advice

hi everyone i have a problem in design as follows: there is a structured file ,for example , field 1, field 2 ....... -------------- -------------- i read it into my memory ,there are some change in the memory maybe add some record or change one field in an existing record. i am going... (1 Reply)
Discussion started by: benbenpig
1 Replies

7. AIX

please give me a script

Hi All, As i asked you in my previous post, I want to read username and lastupdate only from /etc/security/passwd and write the same data to another file: The data in /etc/security/passwd will be in this form for example: smith: password = MGURSj.F056Dj lastupdate = 623078865 flags =... (0 Replies)
Discussion started by: me_haroon
0 Replies

8. UNIX for Dummies Questions & Answers

Give us a hand

How do you get an awk output into columns i.e. awk (print $1,$2,$3) doesn't come out into nice columns but lots of lines of txt want something more like. I am crap at unix so give me a hand thx Rich (3 Replies)
Discussion started by: RichardB
3 Replies
Login or Register to Ask a Question