Contents of file named doexist
* Contents of macro "doexist"
$keys pfx sfx
$default sfx BHE BHN BHZ ;* Default suffix list
sc to scr echo /tmp/temp@$@$.sh ;* Temp script name scr
* Copy text to create a temp. shell script to check if file exists
* Note need to use escape characters for shell script syntax.
$run cat - > %scr%
# This shell script reads a file name and checks whether it exists
# It echos the file name and adds "yes" if it exists or "no"
while read fn ; do
test -f \@$fn @&@& echo \@$fn yes || echo \@$fn no
done
$endrun
sc to finp echo /tmp/temp@$@$.in ;* Temp input file finp
do s list $sfx$ ;* Iterate on suffix list
sc echo $pfx$*.$s$ >> %finp% ;* Add name to input
enddo
sc to inp sh %scr% < %finp% ;* Run script on input
while read inp fn exist ;* Process script output
message "File $fn$ exists? $exist$" ;* Report file existence
enddo
sc rm %scr% %finp% ;* Remove temporary files