Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-05-2012, 11:49 AM   #1
LQ Newbie
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
Creating an alias in ksh that uses grep and includes 'grep -v grep'

I need to create an alias for non-admin programmers who would like to check to see if a process is running on the linux server (kshell). I would like it to auto-exclude the grep process.

alias I would like:
alias psgrep='ps ux | grep $1 | grep -v grep'

example command they would run:
'psgrep webconsole'

However, that errors out. I see the following output:
> psgrep webconsole
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
grep: webconsole: No such file or directory

Old 08-05-2012, 01:21 PM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Strangely enough, it works for me if I switch the order of the greps, e.g.:

alias psgrep="ps ux | grep -v grep | grep $1"
I'm guessing that this is due to some strange way that bash and ksh interpret arguments in aliases, but I can't for the life of me think up why. I guess it's been too long since I've thought about the internals of all this. My suspicion is if you defined this as a function instead of an alias in bash, it should work in the original order, but I haven't tested it.
1 members found this post helpful.
Old 08-05-2012, 02:07 PM   #3
LQ Newbie
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Yes that works! Thank you very much.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
grep has no effect - does not grep anything in this for loopa LinuxChiq Linux - Newbie 2 12-01-2011 09:03 PM
[SOLVED] Grep -p for Linux, Trying to grep a paragraph. ohijames Linux - Newbie 5 07-22-2010 02:09 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration