I am trying to remove the filename extension from a list of files I've generated with the following bash script:
#!/bin/bash
file_list=$(find . -type f) #assuming that the files are stored in the same directory
trimmed_file_list=$(printf '%s\n' "${file_list[@]%.*}")
printf '%s\n' "${trimmed_file_list[@]}"
This expansion trims the extension off the last entry in the list, but not any of the earlier ones.
For example I want the following list:
file1.pdf
file2.pdf
file3.png
To become
file1
file2
file3
But instead I get:
file1.pdf
file2.pdf
file3
I'd prefer not to do this in a loop, I'd like to use parameter expansion. I want to avoid cut because I only ever want to remove the last extension in the file.
There are a fair number of topics on parameter expansion and it appears that bash might be choking on find
's use of newlines... I'm really not sure. If another of the pre-existing topics explains this issue, I don't fully grasp what's going on.
Topics that seem related but don't seem to solve my issue: