kill script using alias name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers kill script using alias name
# 1  
Old 07-03-2010
kill script using alias name

Hi,

I am using the below command to kill the firefox process i have opened in Redhat 5.

Code:
ps -ef|grep fire|grep -v grep|awk '{print $2}'|xargs kill -9

If i execute the above command in terminal it works good and kills session.

but when i use alias for that it is not working.

Code:
alias kill_firefox="ps -ef|grep fire|grep -v grep|awk '{print $2}'|xargs kill -9"

when i run kill_firefox in terminal, i am getting the output as,

Code:
kill : can't find process "root"
killed


But my firefox session still opened and it works.

Share ur thoughts.

Last edited by Scott; 07-03-2010 at 02:34 PM.. Reason: Code tags
# 2  
Old 07-03-2010
one of the problem may be is that the $2 of awk is getting expanded when you are doing the assignment...
# 3  
Old 07-03-2010
Hi.

Also:
Quote:
Aliases are not expanded when the shell is not interactive, unless the
expand_aliases shell option is set using shopt ...

For almost every purpose, aliases are superseded by shell functions.
-- excerpt from man bash q.v., which has more to say on aliases, mostly to the point that one should be using functions instead.

Best wishes ... cheers, drl

Last edited by drl; 07-03-2010 at 10:09 PM.. Reason: ( Edit 1: minor typo )
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute Alias inside script

Hi, in the .profile i have alias jh="cd /var/jdk"What should i write in my unix shell script to use jh and move to /var/jdk directory ? I tried the following in myscript.sh jh $jh $(jh)but none works !! (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

3. Shell Programming and Scripting

Alias has no effect in script

It doesn't have effect in script but it works on the terminal root@server:/opt/kvm/usecases/logs# alias echo='echo -e' root@server:/opt/kvm/usecases/logs# echo "xxxx\n" xxxx root@server:/opt/kvm/usecases/logs# cat xx.sh #!/bin/bash alias echo='echo -n' echo "sssf \n" ... (3 Replies)
Discussion started by: yanglei_fage
3 Replies

4. 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

5. Shell Programming and Scripting

Alias not recognized within script

What would cause a script to work under one user account and not another? Here's an example of what I'm referring to. Here's a simple script. Let's put it in a file called “thescript”. #! /bin/bash alias a='echo hello world' a Here are the results when this script is executed logged in... (3 Replies)
Discussion started by: sszd
3 Replies

6. Shell Programming and Scripting

Using alias in script

Hi all, Could any one tell me how to use aliases in a script i have a large command which launches an application. I want to use alias in the script because i call the application many time in the shell script. Thanks Firestar. (5 Replies)
Discussion started by: firestar
5 Replies

7. UNIX for Advanced & Expert Users

A formatted df script or alias ... ???

Hi gurus, Does anyone have a df script/alias that is sort of "universal"? Just getting frustrated to use bdf for HP-UX, df -h for Linux and Solaris, df -G/g (???) for AIX ... and to make things even worse, some are NFS mount points or with long logical volume name and it extends over two (2)... (1 Reply)
Discussion started by: newbie_01
1 Replies

8. UNIX for Advanced & Expert Users

alias command in script

How can I embed alias command inside the unix script? Script: echo "...." ... ... alias aa=/usr/bin/telnet ... ...The above script is not working. If I type aa hostname in the command prompt 'TELNET' terminal is not opening. Regards,... (2 Replies)
Discussion started by: sharif
2 Replies

9. Shell Programming and Scripting

get command alias name in perl script?

hi all, In my perl script, I need to know the command alias name to make my program flexible. I tried many methods like system("alias cmd"), `alias cmd`, use shell qw,etc. But no one could recognize the built in command alias. If I use `which cmd`, it would look for the command based on... (4 Replies)
Discussion started by: ktmchen
4 Replies

10. Shell Programming and Scripting

Auto Alias Script

Hi All, as you can guess, I'm a newb here, and to shell scripting. I use Linux(CentOS) at home and want to get into scritping. I was creating some aliases on a Laptop the other day, and thought, god this is tedious, and then I thought, heck, why not use it as a 1st script project. Please see... (3 Replies)
Discussion started by: coolboarderguy
3 Replies
Login or Register to Ask a Question