What I am attempting to do is combine all of the files within a subdirectory into a new file, and give the new combined file the same name as the subdirectory, and I have no idea how to do this in Bash. Here's how I approached it: I have a number of directories, each with a unique file name (with spaces!). Within each of these directories, there are a number of numerically named files, like thus:
Home/Unique name/1.pdf
Home/Unique name/2.pdf
Home/Unique name/3.pdf
Home/Unique name/4.pdf
....
Home/Other Unique name/1.pdf
Home/Other Unique name/2.pdf
Home/Other Unique name/3.pdf
Home/Other Unique name/4.pdf
What I would like to do is write a bash script (from the Home
directory) to:
- Go into each unique directory, and perform a command on each of the files within that directory (in my case, copy them all to a different directory).
- I have then written a different script
script.sh
that will perform another command (in this case, combine all the PDFs into a single file,temp.pdf
). I would then like to rename thattemp.pdf
file after the directoryUnique name.pdf
(with spaces). - I will have to follow this process for a number of subdirectories.
I have attempted a solution with a number of for loops, while loops and using the find command, but I am not comfortable enough with bash to debug comfortably or use these variables with any degree of confidence. I am also certain that there is a more efficient way to do what I am doing, but I have bootstrapped the script together over a period of time.
cat
to display them all in the proper order, and pipe the results ofcat
into a new file.