ls | wc -l inside if 语句不起作用

ls | wc -l inside if statement not working

我是qshell新手,想寻求帮助。 我正在尝试使用以下 qshell 命令获取 IFS 目录中的文件数。

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

但是我收到此错误“未预期到令牌词,期待令牌“then”。 TIA

下面的代码片段应该适合您

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

test用于检查条件,$()执行里面的命令