开发者

How to use output from find for if-condition?

I would like that if this command outputs any开发者_运维百科thing

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.


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


Even better you can do it like this:

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

HTH


if find ... | grep . > /dev/null; then
  echo found something
fi

If you need the output:

if h=$(find ... | grep . ); then
  echo found $h
fi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜