Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Alias Syntax Correct?

Alias Syntax Correct?
Thread Tools
Junior Member
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 30, 2003, 05:58 AM
 
hi all,

the following doesn't seem to give the correct output when used as an alias... is the syntax correct?

alias psf "ps -auxww | grep \!:1 | grep -v grep | awk '{print $2}'"
     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Aug 30, 2003, 05:44 PM
 
Yes, it is correct for tcsh.

-
     
zoe77  (op)
Junior Member
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 30, 2003, 09:34 PM
 
thanks for the reply moonray.

thing is it doesn't work when the commands are combined into an alias. the grep results don't seem to be awk'ed.
     
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Aug 31, 2003, 02:41 AM
 
Originally posted by zoe77:
thanks for the reply moonray.

thing is it doesn't work when the commands are combined into an alias. the grep results don't seem to be awk'ed.
Welcome to the hideous world of tcsh quoting. Not a nice place to land. Maybe this will help you out...

alias psf 'ps -auxww | grep \!:1 | grep -v grep | awk '\\''{print $2}'\\'' '

(Yep, *lots* of single quotes in there. Please cut and paste when you're tying it out!) I wish to plead "not guilty" to creating such a monstrous construction: I just hunted around in /usr/share/tcsh/examples/aliases for a similar beast and there it was...

Cheers,
Paul
     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Aug 31, 2003, 07:03 PM
 
Originally posted by zoe77:
thanks for the reply moonray.

thing is it doesn't work when the commands are combined into an alias. the grep results don't seem to be awk'ed.
Oops yes. Sorry I didn't pay attention to that detail. The reason is that the shell expands the $2 if it is enclosed by double (or no) quotes instead of passing it to awk. Paul McCann's version should work fine, or if you want the double quotes, use:

alias psf "ps -auxww | grep \!:1 | grep -v grep | awk '{print "'$2'"}'"

or if you want less quotes:

alias psf ps -auxww | grep \!:1 | grep -v grep | awk '{print $2}'

Hope that helps.

-
     
zoe77  (op)
Junior Member
Join Date: Oct 2000
Status: Offline
Reply With Quote
Aug 31, 2003, 08:12 PM
 
thanks Paul this works perfectly!

Originally posted by Paul McCann:
Welcome to the hideous world of tcsh quoting. Not a nice place to land. Maybe this will help you out...

alias psf 'ps -auxww | grep \!:1 | grep -v grep | awk '\\''{print $2}'\\'' '

Cheers,
Paul
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 10:16 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2