i'll start off by saying I'm a newby when it comes to bash.
I am trying to create a script that would enter all directories and sub-directories (and sub-sub-..-sub-directories) and execute a command on the files inside those directories.
The command I need to run is simply adding a bit of text at the beginning of the file and saving it in (another) file with ".com" at the end of the filename in the same directory as the original.
So far I've been able to create a script that does exactly this but doesn't go deeper than one subdirectory (it won't go into the directories of the directories)
for f in /scratch/aurelien/test/*;
do
[ -d $f ] && cd "$f" &&
for file in ./* ; do printf "TEXT TO ADD TO BEGINNING OF FILE" > ${file}.com &&
tail -n +3 <"$file" >> "${file}.com" ; done &&
done;
After going in circles for a while I've decided to try using Find to do this:
find /scratch/aurelien/test/ -type f -execdir printf "TEXTTOADDTOBEGINNINGOFFILE" > {}.com &&
tail -n +3 <"${}" >> "${}.com" \;
but i'm not sure i've understood well the roll of the {} in the find command, and using execdir I get an error message:
find: The current directory is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove the current directory from your $PATH (that is, remove "." or leading or trailing colons)
Any help would be greatly appreciated !