Operating System - HP-UX
1845992 Members
3841 Online
110252 Solutions
New Discussion

csh syntax to keep a value (variable)

 
SOLVED
Go to solution
Manuales
Super Advisor

csh syntax to keep a value (variable)

hi ..
how can i fix the following syntax using csh?

user15> num_proc=`ps -fea | grep spadm | grep "/usr/sap/SP1" | grep -v grep | wc -l`


num_proc=26: Command not found.

i need to get a number and the command is not being understood

how do i have to use the syntax for chs ?
5 REPLIES 5
Bill Costigan
Honored Contributor
Solution

Re: csh syntax to keep a value (variable)

user15>set num_proc=`ps -fea | grep spadm | grep "/usr/sap/SP1" | grep -v grep | wc -l`

user15>echo $num_proc
Steven E. Protter
Exalted Contributor

Re: csh syntax to keep a value (variable)

Shalom,

I don't do much c-shell but here is a more modern format that works in posix and korn shell

num_proc=$(ps -fea | grep spadm | grep "/usr/sap/SP1" | grep -v grep | wc -l)

Try that. Test your command though you are possibly getting no results.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: csh syntax to keep a value (variable)

Hi Manuales:

# set num_proc=`ps -fea | grep spadm | grep "/usr/sap/SP1" | grep -v grep | wc -l`

# echo $num_proc

Regards!

...JRF...
OldSchool
Honored Contributor

Re: csh syntax to keep a value (variable)

in csh

set num_proc=`ps -fea | grep spadm | grep "/usr/sap/SP1" | grep -v grep | wc -l`

you might also need "setenv", I don't recall. "man csh" will tell you more.....

unless this is minor maintenance to an existing script, consider using something POSIX-compliant for portability sake
James R. Ferguson
Acclaimed Contributor

Re: csh syntax to keep a value (variable)

Hi (again) Manuales:

I can't resist adding that the use of the *C*rummy C-shell will cause great gnashing of your teeth and others. In the HP-UX world, the POSIX shell ('/usr/bin/sh' or '/sbin/sh' for the root user)' is the standard. You should read this classic:

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Regards!

...JRF...