I have a series of zipped files with standardized names (file1pop.zip, ..., filenpop.zip). Inside each of these files, I have a file of interest popdnamei.asc, with i={1,n}. I want to execute two commands on these files (among which converting the asc files to tif). However, I can't get my bash script to work. I think I am not understanding correctly how to chop strings on bash. Does anybody know which is my mistake?
###################
## Choose path
###################
cd
cd path/to/my/directory/with/zipfiles
###################
## Unzip, convert to tif and project (WGS84)
###################
for x in *pop.zip
do
echo $x
files=${x%%.*} #with this I hope to target the base name "filei", i={1,n} without the ".zip" extension
mkdir $files
unzip -d $files $x
y=popd*.asc
if [ -f $files/$y ] #with this I want to run my commands only if the file popdnamei.asc does exist in the file
then
newy=${y%%.*} #extract "popdnamei" without ".asc" extension
gdal_translate $files/$y $files/$newy.tif #command 1
gdalwarp -s_srs "WGS84" -t_srs "WGS84" $files/$newy.tif $files/$newy_PROJ.tif #command 2
cp $files/$newy_PROJ.tif ../Output_Storage/
fi
rm -rf $files
done
I think I have a problem with variable $y
. I checked while the program was running and the output files are literally named "newypopd*.tif
" with the asterisk instead of being named with the "completed" name (popdnamei.tif
). Moreover no file is written to my Output_Storage directory. I think I have a trouble chopping a variable defined with an asterisk for completion, and I am not fully understanding what it is. Can somebody help me?
Thank you.