Assuming that you are using the bash
shell:
shopt -s globstar nullglob dotglob
./avg outAVG ./**/*B02_10m.tif
This would call your avg
program with all the files in or below the current directory that have filenames ending in B02_10m.tif
. It does this by first enabling the **
globbing pattern with shopt -s globstar
. This pattern matches "recursively" down into subdirectories. If your TIFF files are in the current directory, you don't need the **
bit of this pattern.
The other two shell options makes sure that globbing patterns matches hidden names and that they expand to nothing at all if there is no match, just to mimic what you're trying to do with find
.
If you are using the zsh
shell, then you may instead use
./avg outAVG ./**/*B02_10m.tif(.DN)
which would do the same. Again, if you know the directory where the TIFF images are stored, you don't need the **
bit of the pattern but can instead insert the correct path to that directory.
In any sh
-like shell, if your files are in the directory named by $dir
, you may use
./avg outAVG "$dir"/*B02_10m.tif
This would obviously not do a recursive search down into subdirectories of $dir
.
Your approach does not work for two reasons:
You have a syntax error in the assignment to the files
variable. There can be no whitespace around the =
in an assignment.
Correcting that syntax error, you are combining many separate filenames into a single string. Doing this disregards the fact that filenames may well include spaces and characters usually used as shell wildcards. When you later use $files
unquoted, the shell would split the string inte several words on whitespace characters (by default) and then expand all words that looks like shell globbing patterns. This would make your code misbehave if you don't always have very simple filenames.
For more information about these issues, see e.g.
bash
orzsh
? Storing the filenames in a string is most likely not what you want to do. – Kusalananda Dec 03 '19 at 06:58avg: avg.c gcc -o avg avg.c -lm -I/usr/include/gdal -L/usr/lib -lgdal run.sh
root=/home/user/Dir/ files=$(ls $rootsatelliteimages) ./avg outAVG $files
*/
– Roger Almengor Dec 03 '19 at 07:04files=$(ls $root*satelliteimages)
for the results that I get when running the command find and the arguments I already presented. – Roger Almengor Dec 03 '19 at 07:05$root*satelliteimages
looks strange). – Kusalananda Dec 03 '19 at 07:14