How to test the output only contains a specific string
I use following shell script
Revised code Code:
host_list="/home/campus27/zwang10/bin/hostlist" **Under the condition that Code:
[ $RESULT -eq 0 ] either Code:
[ -z $(ssh -f $line "w" | tail -n+3 | awk '{print $1}') ] Code:
$(ssh -f $line "w" | tail -n+3 | awk '{print $1}') only contains string "zwang10" The command Code:
$(ssh -f $line "w" | tail -n+3 | awk '{print $1}') ] Only one of my name Code:
zwang10 Code:
Code:
jack Code:
jack Revised requirement Code:
$output == 'zwang10' Code:
zwang10 |
You seem to be of aware numeric comparisons (and -z which is a string operator) in test, so just use the string comparison operator(s).
|
The shell string match [[ == ]] has a problem with exact line match.
That's why I'd use grep here Code:
if ssh ... | fgrep -xq zwang10 |
Single "=" with enhanced test should work.
Yeah, I know, "==" makes more sense if you've done any real programming. |
Quote:
|
Quote:
|
Based on your revised code.
Code:
host_list="/home/campus27/zwang10/bin/hostlist" |
All times are GMT -5. The time now is 12:01 AM. |