I would like to check the existence of files (doesn;t matter the number of files) in a directory.
My file is named in the following manner (always ending with " myfile "). Can anybody give me some guidance?
EG:
abc1_myfile
sdfr_myfile
sffgd_myfile
and so on ......
My intention is to perform the following:
if file exist, perform plan A.
else perform plan B.
I'm a bit rusty on csh, since I never use it but if I remember correctly from when we had a bunch of users to support who did use it, the syntax would be something like:
foreach file ( *_myfile )
echo $file
end
or if you want the action a or action b
ls *_myfile >& /dev/null
if ( $status == 0 ) then
foreach file ( *_myfile )
echo $file
end
else
echo "no files"
endif
I tried the " $status " in a directory containing *myfile.
And these statement appear " Reset tty pgrp from 7873 to 11434 ". What does this statement mean ?
Is " $status " a special variable in csh ?
% ls *myfile
xxx1_myfile xxx2_myfile
% ls *myfile|echo $status
0
% Reset tty pgrp from 7873 to 11434
But what's your purpose of this statement " ls *_myfile >& /dev/null " before the statement " if ( $status == 0 ) then ". My code " ls *myfile|echo $status " was emulating this.
I tried to perform "echo $status" in a directory with files and in a directory without files, the output is always " 0 ". So what does $status really mean ?