Hi. I expect the following unix script command to return 8:
ls -ltr dropez* | grep -c dropez
I can't seem to find the correct syntax (borne shell), can anyone help be to write an IF condition something like this:
IF (ls -ltr dropez* | grep -c dropez) = 8 THEN
...do stuff
ELSE
...do other stuff
END IF
#!/bin/sh
if [ `ls -ltr dropez* | grep -c dropez` -eq 8 ]; then
do stuff
else
do other stuff
fi
1 Like
Thanks so much for taking the time to help. Much appreciated.
#!/bin/ksh
CHECKFOUND=`ls -ltr dropez* | grep -c dropez`
if [[ ${CHECKFOUND} -eq "8" ]]
then
do stuff
else
do other stuff
fi
this solution is very similar, but In this way, you have available the counter "${CHECKFOUND}"
if ( set -- dropez*; [ $# -eq 8 ] ); then
..do stuff
else
..do other stuff
fi