I try to loop through two directories and echo all files with a given extension with this script:
#!/bin/bash
FOLDERS=/sdd/DATA/ /sdc/storage/
for d in $FOLDERS; do
echo "$d"
FILES=$d*.txt
for f in $FILES; do
echo "$f"
done
done
but I do not get this script to work! I get bash: sdc/storage/ is a directory
-bash: /sdc/storage: is a directory/sdd/DATA/ /sdc/storage/in quotation marks. (Without, that line setsFOLDERS=/sdd/DATA/and then attempts to execute/sdc/storage/, which doesn't work because -- guess what -- it's a directory. ;-) ) Even better would be to be aware of filenames with spaces in them, and either doing "the IFS thing" withfor ... in ..., or usingfind ... -exec ....FOLDERSas a string rather than an array. Aiming for the most obvious issue first, it'd break the moment you had a directory name with spaces.