![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| output of command rup | kiranrasane | UNIX for Advanced & Expert Users | 1 | 03-27-2008 06:31 AM |
| ls command output | arsheshadri | AIX | 1 | 08-20-2007 03:23 AM |
| Output of ps -ef command | dbrundrett | UNIX for Advanced & Expert Users | 6 | 01-06-2005 10:48 AM |
| Output of ps command | ls1429 | UNIX for Dummies Questions & Answers | 1 | 02-03-2003 06:40 AM |
| Output command | berty007 | Shell Programming and Scripting | 4 | 11-29-2002 01:27 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
if command not having the right output
Code:
if cat /var/log/messages | grep fail = " " then echo "Good" else echo "Bad" fi |
| Forum Sponsor | ||
|
|
|
|||
|
You need backquotes to capture output
Then double quotes to make it a single argument for test And you need test And it should be a truely empty string Code:
if test "`cat /var/log/messages | grep fail`" = "" then echo "Good" else echo "Bad" fi Code:
if test -z "`cat /var/log/messages | grep fail`" ... Code:
if grep fail /var/log/messages
then
echo failed
else
echo no problems
fi
|
|
|||
|
Code:
#!/bin/sh
LOG_FILE=log.txt
grep -l fail /var/log/messages* > $LOG_FILE
if [$? -eq 0]
then
echo "Bad"
echo "Files that contains failures are"
cat $LOG_FILE
else
echo "Good"
fi
exit
$? ==> unknown variable or all variable ? -eq ==> equals ? |