-3

Goal: Checking find result, if empty echo something, if not echo find result

#!/bin/csh
set mtime = 0;
echo "<i>Title</i>" >> $outputfile
set text=`find start*middle*.txt -mtime $mtime -ls`
echo "$text" >> $outputfile

I have tried the following (all failed) ...

if (-f "$text" ) then
    echo Exists
else
    echo No such file
endif

-

if [[ -n $(find start*middle*.txt -mtime $mtime -ls) ]]
then
 echo "res" >> $outputfile
fi

-

if [[ -n "$text" ]]
then
 echo "res" >> $outputfile
fi
pynexj
  • 19,215
  • 5
  • 38
  • 56
DavidDunham
  • 1,245
  • 1
  • 22
  • 44

1 Answers1

0
#!/bin/csh
set outputfile = test
set mtime = 0;
echo "<i>Title</i>" >> $outputfile
set text=`find start*middle*.txt -ls`
if ("$text" != "") then
        echo "exists"
else
        echo "dosn't exist"
endif
echo "$text" >> $outputfile

If you need to use the -mtime option a value of 0 is incorrect. If you want to list files created in the last day you need -mtime -1 and for 2 days -mtime -2

Orion
  • 477
  • 2
  • 4
  • 13