Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use output from find for if-condition?

Tags:

linux

bash

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.

like image 936
Sandra Schlichting Avatar asked Oct 15 '25 10:10

Sandra Schlichting


1 Answers

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.

like image 190
Eugene Yarmash Avatar answered Oct 17 '25 03:10

Eugene Yarmash