I want to set the number of a particular process that are running to a variable. The first line of the csh script below is the problem as it sets the variable "number" as ps aux | grep -c fiji instead of the output of ps aux | grep -c fiji which should be 1.

#!/bin/csh

set number = 'ps aux | grep -c fiji'

if ( $number <= 1 ) then
(I run a command here)
else
echo $number
endif
link|improve this question

0% accept rate
feedback

2 Answers

You should use backtics (`), not single quotes ('). This script

#!/bin/csh

set number = `ps aux | grep -c fiji`

echo $number

prints 1

link|improve this answer
feedback

general remark: your command will always return 1 or more, including the process you run for the grep. So you need to take care of this after evaluation, or use something like pgrep.

And then - csh. Have a look at http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ . And http://www.grymoire.com/Unix/CshTop10.txt .

still want to use csh ;-) ?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.