Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

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 ;-) ?

share|improve this answer
add comment

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

#!/bin/csh

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

echo $number

prints 1

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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