ls | wc -l inside if statement not working

175 Views Asked by At

I am new in qshell and would like to ask for assistance. I am trying to get the file count inside an IFS directory using below qshell command.

if(ls <<path>> | wc -l) -gt 0;                    
then echo correct;                                                
fi  

however im getting this error "token word not expected, expecting token "then". TIA

1

There are 1 best solutions below

0
Tamil Selvan V On BEST ANSWER

The below snippet should work for you

if test $(ls <<path>> | wc -l) -gt 0;
then echo correct;
fi

test is used to check the condition, and $() executes the command present inside