当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - How to use output from find for if-condition?

问题描述:

I would like that if this command outputs anything

find /var/www/cgi-bin -name touch -cmin 10

then should "ok" be echoed.

Have tried

if [ $(find /var/www/cgi-bin -name touch -cmin 10) ]; then echo "ok";fi

but it never echoes anything.

网友答案:

Even better you can do it like this:

find /var/www/cgi-bin -name touch -cmin 10 -exec echo "ok" \;

HTH

网友答案:

Put double quotes around $(..):

if [ "$(find /var/www/cgi-bin -name touch -cmin 10)" ]; then echo "ok"; fi

This will interpret the output of find as a single word.

网友答案:

This should work for you

if [ -n "$(find ./var/www/cgi-bin -name touch -cmin 10)" ];then echo ok;fi

网友答案:
if find ... | grep . > /dev/null; then
  echo found something
fi

If you need the output:

if h=$(find ... | grep . ); then
  echo found $h
fi
分享给朋友:
您可能感兴趣的文章:
随机阅读: