Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conditional question

 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about this newbie question but I am new scripting.
Here is my script.

#!/bin/bash
if [ ps -axf|grep -c "/sbin/mingetty" -eq 6 ]; then
echo yep
else
echo nope
fi

I have also tried this with single quotes around /sbin/mingetty and with cancelled parentheses for better grouping. When I run it as above, I get the followin lines.
test: [: missing `]'
/sbin/mingetty:3
grep: 6: No such file or directory
grep: ]: No such file or directory
nope
for some reason it looks like it is not grouping correctly. Any ideas?
 
James O'Dell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
You just need to put backticks (`) around your ps command:

The backticks execute the command and return the value in place.
The "backtick" is the character that's usually on the same key as the tilda (~) for those that may not be familiar with the term.
Jim
[ September 02, 2002: Message edited by: James O'Dell ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic