If this is on Linux/Unix, can you use the find
command? That seems very much like fetchkeys
.
$ find . -name "*foo*.fit" -type f -print0 | while read -r -d $'\0' file
do
basename=$(basename $file)
cp "$file" "$fits_dir/$basename"
done
The find
command will find all files that match *foo*.fits
in their name. The -type f
says they have to be files and not directories. The -print0
means print out the files found, but separate them with the NUL character. Normally, the find
command will simply return a file on each line, but what if the file name contains spaces, tabs, new lines, or even other strange characters?
The -print0
will separate out files with nulls (\0), and the read -d $'\0' file
means to read in each file separating by these null characters. If your files don't contain whitespace or strange characters, you could do this:
$ find . -name "*foo*.fit" -type f | while read file
do
basename=$(basename $file)
cp "$file" "$fits_dir/$basename"
done
Basically, you read each file found with your find command into the shell variable file
. Then, you can use that to copy that file into your $fits_dir
or where ever you want.
Again, maybe there's a reason to use fetchKeys
, and it is possible to replace that find
with fetchKeys
, but I don't know that fetchKeys
command.