I'm trying to write one line of code that finds all .sh
files in the current directory and its subdirectories, and print them without the .sh
extension (preferably without the path too).
I think I got the find
command down. I tried using the output of
find . -type f -iname "*.sh" -print
as input for echo
, and formatting it along these lines
echo "${find_output%.sh}"
However, I cannot get it to work in one line, without variable assigment. I got inspiration from this answer on stackoverflow https://stackoverflow.com/a/18639136/15124805 to use this line:
echo "${$( find . -type f -iname "*.sh" -print)%.sh}"
But I get this error:
ash: ${$( find . -type f -iname "*.sh" -print)%.sh}: bad substitution
I also tried using xargs
find . -type f -iname "*.sh" -print |"${xargs%.sh}" echo
But I get a "command not found error" -probably I didn't use xargs
correctly, but I'm not sure how I could improve this or if it's the right way to go.
How can I make this work?