How to remove filename extension from a list of filenames in bash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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 '%sn' "$file_list[@]%.*")
printf '%sn' "$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:



  • How can I remove the extension of a filename in a shell script?

  • Shell parameter expansion on arrays

  • Dropping filename extensions with find -exec









share|improve this question























  • Your title mentions arrays, but there is no array in your code.
    – Kusalananda
    Aug 14 at 8:08










  • @Kusalananda Thank you! I've come to realize that since asking. Still learning :)
    – Shrout1
    Aug 14 at 13:04










  • @Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
    – Shrout1
    Aug 14 at 14:05














up vote
0
down vote

favorite












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 '%sn' "$file_list[@]%.*")
printf '%sn' "$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:



  • How can I remove the extension of a filename in a shell script?

  • Shell parameter expansion on arrays

  • Dropping filename extensions with find -exec









share|improve this question























  • Your title mentions arrays, but there is no array in your code.
    – Kusalananda
    Aug 14 at 8:08










  • @Kusalananda Thank you! I've come to realize that since asking. Still learning :)
    – Shrout1
    Aug 14 at 13:04










  • @Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
    – Shrout1
    Aug 14 at 14:05












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 '%sn' "$file_list[@]%.*")
printf '%sn' "$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:



  • How can I remove the extension of a filename in a shell script?

  • Shell parameter expansion on arrays

  • Dropping filename extensions with find -exec









share|improve this question















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 '%sn' "$file_list[@]%.*")
printf '%sn' "$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:



  • How can I remove the extension of a filename in a shell script?

  • Shell parameter expansion on arrays

  • Dropping filename extensions with find -exec






bash find string printf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 14 at 14:04

























asked Aug 13 at 20:49









Shrout1

144119




144119











  • Your title mentions arrays, but there is no array in your code.
    – Kusalananda
    Aug 14 at 8:08










  • @Kusalananda Thank you! I've come to realize that since asking. Still learning :)
    – Shrout1
    Aug 14 at 13:04










  • @Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
    – Shrout1
    Aug 14 at 14:05
















  • Your title mentions arrays, but there is no array in your code.
    – Kusalananda
    Aug 14 at 8:08










  • @Kusalananda Thank you! I've come to realize that since asking. Still learning :)
    – Shrout1
    Aug 14 at 13:04










  • @Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
    – Shrout1
    Aug 14 at 14:05















Your title mentions arrays, but there is no array in your code.
– Kusalananda
Aug 14 at 8:08




Your title mentions arrays, but there is no array in your code.
– Kusalananda
Aug 14 at 8:08












@Kusalananda Thank you! I've come to realize that since asking. Still learning :)
– Shrout1
Aug 14 at 13:04




@Kusalananda Thank you! I've come to realize that since asking. Still learning :)
– Shrout1
Aug 14 at 13:04












@Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
– Shrout1
Aug 14 at 14:05




@Kusalananda I've gone ahead and modified the question to more closely match the problem. That should prevent erroneous google searches from hitting the page. Thank you for the information!
– Shrout1
Aug 14 at 14:05










3 Answers
3






active

oldest

votes

















up vote
3
down vote













You could do all in one command.



find /path/to -type f -execdir bash -c 'printf "%sn" "$@%.*"' bash +





share|improve this answer






















  • Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
    – Shrout1
    Aug 14 at 13:24

















up vote
1
down vote













Your code does not include any arrays. Also, it puts a list of filenames into a string, $file_list. The contents of the string will end with file3.png and your parameter substitution removes .png from the string, leaving you with a single string of filenames where the last filename does not have a filename suffix.



Putting multiple separate objects (pathnames) into a single string automatically disqualifies the script from working properly for files whose names contains spaces (or whatever delimiter the string uses). Using an array would not help as you would still split the output of find on whitespaces.




To trim the extension off of all filenames of regular files in or below the current directory:



find . -type f -name "*.*" -exec sh -c '
for pathname do
printf "Would move %s to %s...n" "$pathname" "$pathname%.*"
# mv -i "$pathname" "$pathname%.*"
done' sh +


This looks for regular files whose names contains at least one dot. The pathnames of these files are fed in batches into a small shell script that loops over them. The shell script renames the files by removing the last dot in the filename and everything that comes after. The actual mv command is commented out for safety.



The find command acts as a generator of pathnames for the internal shell script, and we are guaranteed to properly process pathnames containing spaces, newlines and tabs. There is no need for storing the output of commands in variables.



If you have an array of pathnames, possibly created by using



shopt -s globstar nullglob
file_list=( **/*.* ) # get pathnames of files with dots in their names


Then you would be able to output the pathnames without suffixes with



printf '%sn' "$file_list[@]%.*"


Whether this would help you, I don't know. If you want to use the pathnames with no suffixes for something, then using the output of the above printf command would be the wrong thing to do (you would be back at not handling strange pathname again). So when and how you delete the filename suffixes depends on what you'd like to do with the result.



Related:



  • Understanding the -exec option of `find`

  • Why is looping over find's output bad practice?





share|improve this answer






















  • Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
    – Shrout1
    Aug 14 at 13:25


















up vote
1
down vote













I believe you would want to make an array instead of a string:



IFS=$'n' # split on newline only
set -o noglob # disable the glob part
file_list=($(find . -name '*.*' -type f))


Or with bash 4.4+, not breaking on file paths with newline characters:



readarray -td '' file_list < <(find . -name '*.*' -type f -print0)


Then your parameter expansion should work, though here it would make more sense to use an array variable again:



trimmed_file_list=("$file_list[@]%.*")


In your code sample, you are making a string then asking parameter expansion to remove everything after the final dot character in the full string.






share|improve this answer






















  • Thank you! I’ll test it as soon as I hit my desk in the morning.
    – Shrout1
    Aug 13 at 23:07










  • This assumes that no filenames in that directory contain any whitespace or globbing characters.
    – Wildcard
    Aug 14 at 3:48










  • @Wildcard, should be addressed by the latest edit.
    – Stéphane Chazelas
    Aug 14 at 9:06










  • @Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
    – Shrout1
    Aug 14 at 13:08










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462385%2fhow-to-remove-filename-extension-from-a-list-of-filenames-in-bash%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













You could do all in one command.



find /path/to -type f -execdir bash -c 'printf "%sn" "$@%.*"' bash +





share|improve this answer






















  • Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
    – Shrout1
    Aug 14 at 13:24














up vote
3
down vote













You could do all in one command.



find /path/to -type f -execdir bash -c 'printf "%sn" "$@%.*"' bash +





share|improve this answer






















  • Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
    – Shrout1
    Aug 14 at 13:24












up vote
3
down vote










up vote
3
down vote









You could do all in one command.



find /path/to -type f -execdir bash -c 'printf "%sn" "$@%.*"' bash +





share|improve this answer














You could do all in one command.



find /path/to -type f -execdir bash -c 'printf "%sn" "$@%.*"' bash +






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 9:22









Stéphane Chazelas

284k53524862




284k53524862










answered Aug 14 at 2:50









αғsнιη

15.7k92563




15.7k92563











  • Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
    – Shrout1
    Aug 14 at 13:24
















  • Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
    – Shrout1
    Aug 14 at 13:24















Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
– Shrout1
Aug 14 at 13:24




Thank you! I actually need to create a couple copies of the array, one for a menu that has the filename modified and one that will retain the original index value so that I can call the file from the menu. It is truly amazing how much bash can do though! The ability to embed everything into one command still blows me away! :D
– Shrout1
Aug 14 at 13:24












up vote
1
down vote













Your code does not include any arrays. Also, it puts a list of filenames into a string, $file_list. The contents of the string will end with file3.png and your parameter substitution removes .png from the string, leaving you with a single string of filenames where the last filename does not have a filename suffix.



Putting multiple separate objects (pathnames) into a single string automatically disqualifies the script from working properly for files whose names contains spaces (or whatever delimiter the string uses). Using an array would not help as you would still split the output of find on whitespaces.




To trim the extension off of all filenames of regular files in or below the current directory:



find . -type f -name "*.*" -exec sh -c '
for pathname do
printf "Would move %s to %s...n" "$pathname" "$pathname%.*"
# mv -i "$pathname" "$pathname%.*"
done' sh +


This looks for regular files whose names contains at least one dot. The pathnames of these files are fed in batches into a small shell script that loops over them. The shell script renames the files by removing the last dot in the filename and everything that comes after. The actual mv command is commented out for safety.



The find command acts as a generator of pathnames for the internal shell script, and we are guaranteed to properly process pathnames containing spaces, newlines and tabs. There is no need for storing the output of commands in variables.



If you have an array of pathnames, possibly created by using



shopt -s globstar nullglob
file_list=( **/*.* ) # get pathnames of files with dots in their names


Then you would be able to output the pathnames without suffixes with



printf '%sn' "$file_list[@]%.*"


Whether this would help you, I don't know. If you want to use the pathnames with no suffixes for something, then using the output of the above printf command would be the wrong thing to do (you would be back at not handling strange pathname again). So when and how you delete the filename suffixes depends on what you'd like to do with the result.



Related:



  • Understanding the -exec option of `find`

  • Why is looping over find's output bad practice?





share|improve this answer






















  • Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
    – Shrout1
    Aug 14 at 13:25















up vote
1
down vote













Your code does not include any arrays. Also, it puts a list of filenames into a string, $file_list. The contents of the string will end with file3.png and your parameter substitution removes .png from the string, leaving you with a single string of filenames where the last filename does not have a filename suffix.



Putting multiple separate objects (pathnames) into a single string automatically disqualifies the script from working properly for files whose names contains spaces (or whatever delimiter the string uses). Using an array would not help as you would still split the output of find on whitespaces.




To trim the extension off of all filenames of regular files in or below the current directory:



find . -type f -name "*.*" -exec sh -c '
for pathname do
printf "Would move %s to %s...n" "$pathname" "$pathname%.*"
# mv -i "$pathname" "$pathname%.*"
done' sh +


This looks for regular files whose names contains at least one dot. The pathnames of these files are fed in batches into a small shell script that loops over them. The shell script renames the files by removing the last dot in the filename and everything that comes after. The actual mv command is commented out for safety.



The find command acts as a generator of pathnames for the internal shell script, and we are guaranteed to properly process pathnames containing spaces, newlines and tabs. There is no need for storing the output of commands in variables.



If you have an array of pathnames, possibly created by using



shopt -s globstar nullglob
file_list=( **/*.* ) # get pathnames of files with dots in their names


Then you would be able to output the pathnames without suffixes with



printf '%sn' "$file_list[@]%.*"


Whether this would help you, I don't know. If you want to use the pathnames with no suffixes for something, then using the output of the above printf command would be the wrong thing to do (you would be back at not handling strange pathname again). So when and how you delete the filename suffixes depends on what you'd like to do with the result.



Related:



  • Understanding the -exec option of `find`

  • Why is looping over find's output bad practice?





share|improve this answer






















  • Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
    – Shrout1
    Aug 14 at 13:25













up vote
1
down vote










up vote
1
down vote









Your code does not include any arrays. Also, it puts a list of filenames into a string, $file_list. The contents of the string will end with file3.png and your parameter substitution removes .png from the string, leaving you with a single string of filenames where the last filename does not have a filename suffix.



Putting multiple separate objects (pathnames) into a single string automatically disqualifies the script from working properly for files whose names contains spaces (or whatever delimiter the string uses). Using an array would not help as you would still split the output of find on whitespaces.




To trim the extension off of all filenames of regular files in or below the current directory:



find . -type f -name "*.*" -exec sh -c '
for pathname do
printf "Would move %s to %s...n" "$pathname" "$pathname%.*"
# mv -i "$pathname" "$pathname%.*"
done' sh +


This looks for regular files whose names contains at least one dot. The pathnames of these files are fed in batches into a small shell script that loops over them. The shell script renames the files by removing the last dot in the filename and everything that comes after. The actual mv command is commented out for safety.



The find command acts as a generator of pathnames for the internal shell script, and we are guaranteed to properly process pathnames containing spaces, newlines and tabs. There is no need for storing the output of commands in variables.



If you have an array of pathnames, possibly created by using



shopt -s globstar nullglob
file_list=( **/*.* ) # get pathnames of files with dots in their names


Then you would be able to output the pathnames without suffixes with



printf '%sn' "$file_list[@]%.*"


Whether this would help you, I don't know. If you want to use the pathnames with no suffixes for something, then using the output of the above printf command would be the wrong thing to do (you would be back at not handling strange pathname again). So when and how you delete the filename suffixes depends on what you'd like to do with the result.



Related:



  • Understanding the -exec option of `find`

  • Why is looping over find's output bad practice?





share|improve this answer














Your code does not include any arrays. Also, it puts a list of filenames into a string, $file_list. The contents of the string will end with file3.png and your parameter substitution removes .png from the string, leaving you with a single string of filenames where the last filename does not have a filename suffix.



Putting multiple separate objects (pathnames) into a single string automatically disqualifies the script from working properly for files whose names contains spaces (or whatever delimiter the string uses). Using an array would not help as you would still split the output of find on whitespaces.




To trim the extension off of all filenames of regular files in or below the current directory:



find . -type f -name "*.*" -exec sh -c '
for pathname do
printf "Would move %s to %s...n" "$pathname" "$pathname%.*"
# mv -i "$pathname" "$pathname%.*"
done' sh +


This looks for regular files whose names contains at least one dot. The pathnames of these files are fed in batches into a small shell script that loops over them. The shell script renames the files by removing the last dot in the filename and everything that comes after. The actual mv command is commented out for safety.



The find command acts as a generator of pathnames for the internal shell script, and we are guaranteed to properly process pathnames containing spaces, newlines and tabs. There is no need for storing the output of commands in variables.



If you have an array of pathnames, possibly created by using



shopt -s globstar nullglob
file_list=( **/*.* ) # get pathnames of files with dots in their names


Then you would be able to output the pathnames without suffixes with



printf '%sn' "$file_list[@]%.*"


Whether this would help you, I don't know. If you want to use the pathnames with no suffixes for something, then using the output of the above printf command would be the wrong thing to do (you would be back at not handling strange pathname again). So when and how you delete the filename suffixes depends on what you'd like to do with the result.



Related:



  • Understanding the -exec option of `find`

  • Why is looping over find's output bad practice?






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 8:48

























answered Aug 14 at 8:13









Kusalananda

106k14209327




106k14209327











  • Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
    – Shrout1
    Aug 14 at 13:25

















  • Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
    – Shrout1
    Aug 14 at 13:25
















Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
– Shrout1
Aug 14 at 13:25





Thank you! Your mastery of bash is very evident! I'm still scraping at the surface... Thank you for taking the time to help :)
– Shrout1
Aug 14 at 13:25











up vote
1
down vote













I believe you would want to make an array instead of a string:



IFS=$'n' # split on newline only
set -o noglob # disable the glob part
file_list=($(find . -name '*.*' -type f))


Or with bash 4.4+, not breaking on file paths with newline characters:



readarray -td '' file_list < <(find . -name '*.*' -type f -print0)


Then your parameter expansion should work, though here it would make more sense to use an array variable again:



trimmed_file_list=("$file_list[@]%.*")


In your code sample, you are making a string then asking parameter expansion to remove everything after the final dot character in the full string.






share|improve this answer






















  • Thank you! I’ll test it as soon as I hit my desk in the morning.
    – Shrout1
    Aug 13 at 23:07










  • This assumes that no filenames in that directory contain any whitespace or globbing characters.
    – Wildcard
    Aug 14 at 3:48










  • @Wildcard, should be addressed by the latest edit.
    – Stéphane Chazelas
    Aug 14 at 9:06










  • @Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
    – Shrout1
    Aug 14 at 13:08














up vote
1
down vote













I believe you would want to make an array instead of a string:



IFS=$'n' # split on newline only
set -o noglob # disable the glob part
file_list=($(find . -name '*.*' -type f))


Or with bash 4.4+, not breaking on file paths with newline characters:



readarray -td '' file_list < <(find . -name '*.*' -type f -print0)


Then your parameter expansion should work, though here it would make more sense to use an array variable again:



trimmed_file_list=("$file_list[@]%.*")


In your code sample, you are making a string then asking parameter expansion to remove everything after the final dot character in the full string.






share|improve this answer






















  • Thank you! I’ll test it as soon as I hit my desk in the morning.
    – Shrout1
    Aug 13 at 23:07










  • This assumes that no filenames in that directory contain any whitespace or globbing characters.
    – Wildcard
    Aug 14 at 3:48










  • @Wildcard, should be addressed by the latest edit.
    – Stéphane Chazelas
    Aug 14 at 9:06










  • @Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
    – Shrout1
    Aug 14 at 13:08












up vote
1
down vote










up vote
1
down vote









I believe you would want to make an array instead of a string:



IFS=$'n' # split on newline only
set -o noglob # disable the glob part
file_list=($(find . -name '*.*' -type f))


Or with bash 4.4+, not breaking on file paths with newline characters:



readarray -td '' file_list < <(find . -name '*.*' -type f -print0)


Then your parameter expansion should work, though here it would make more sense to use an array variable again:



trimmed_file_list=("$file_list[@]%.*")


In your code sample, you are making a string then asking parameter expansion to remove everything after the final dot character in the full string.






share|improve this answer














I believe you would want to make an array instead of a string:



IFS=$'n' # split on newline only
set -o noglob # disable the glob part
file_list=($(find . -name '*.*' -type f))


Or with bash 4.4+, not breaking on file paths with newline characters:



readarray -td '' file_list < <(find . -name '*.*' -type f -print0)


Then your parameter expansion should work, though here it would make more sense to use an array variable again:



trimmed_file_list=("$file_list[@]%.*")


In your code sample, you are making a string then asking parameter expansion to remove everything after the final dot character in the full string.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 9:06









Stéphane Chazelas

284k53524862




284k53524862










answered Aug 13 at 22:09









GracefulRestart

76917




76917











  • Thank you! I’ll test it as soon as I hit my desk in the morning.
    – Shrout1
    Aug 13 at 23:07










  • This assumes that no filenames in that directory contain any whitespace or globbing characters.
    – Wildcard
    Aug 14 at 3:48










  • @Wildcard, should be addressed by the latest edit.
    – Stéphane Chazelas
    Aug 14 at 9:06










  • @Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
    – Shrout1
    Aug 14 at 13:08
















  • Thank you! I’ll test it as soon as I hit my desk in the morning.
    – Shrout1
    Aug 13 at 23:07










  • This assumes that no filenames in that directory contain any whitespace or globbing characters.
    – Wildcard
    Aug 14 at 3:48










  • @Wildcard, should be addressed by the latest edit.
    – Stéphane Chazelas
    Aug 14 at 9:06










  • @Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
    – Shrout1
    Aug 14 at 13:08















Thank you! I’ll test it as soon as I hit my desk in the morning.
– Shrout1
Aug 13 at 23:07




Thank you! I’ll test it as soon as I hit my desk in the morning.
– Shrout1
Aug 13 at 23:07












This assumes that no filenames in that directory contain any whitespace or globbing characters.
– Wildcard
Aug 14 at 3:48




This assumes that no filenames in that directory contain any whitespace or globbing characters.
– Wildcard
Aug 14 at 3:48












@Wildcard, should be addressed by the latest edit.
– Stéphane Chazelas
Aug 14 at 9:06




@Wildcard, should be addressed by the latest edit.
– Stéphane Chazelas
Aug 14 at 9:06












@Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
– Shrout1
Aug 14 at 13:08




@Wildcard Thanks for the pointer! I'm generating the files that are dropped into this directory programmatically so it shouldn't be a problem.
– Shrout1
Aug 14 at 13:08

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462385%2fhow-to-remove-filename-extension-from-a-list-of-filenames-in-bash%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?