-5

command line that searches for all file names in the directory. file names without the .sh

Example of output:

$>./file.sh -e

closed as unclear what you're asking by Jeff Schaller, Scott, Anthon, Satō Katsura, GAD3R Sep 13 '17 at 9:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Example of output: – Serg Sep 12 '17 at 20:15
  • $>./find_sh.sh | cat -e – Serg Sep 12 '17 at 20:16
  • 4
    Don't add comments to your question to expand the question; just edit the question to add the detail. – DopeGhoti Sep 12 '17 at 20:27
  • 1
    Where is the question? I do hope you realise this a Q&A site and the Q stands for question. – Anthon Sep 13 '17 at 6:16
  • 2
    Multiposted at stackoverflow.com/questions/46191181 under a different account. Also on non-StackExchange sites such as at eadiscussion.com/index.php?threads/… . – JdeBP Sep 13 '17 at 7:26
2
find . -name \*.sh | sed 's/\.sh$//'

or

find . -name \*.sh -print0 | xargs -0 basename -a -s .sh "{}" \;
  • Worth pointing out that that last one requires basename from GNU coreutils. – Kusalananda Sep 12 '17 at 22:13
1

Using bash:

shopt -s globstar
for f in **/*.sh; do printf '%s\n' "${f%*.sh}"; done
1
find . -type f -name '*.sh' \
    -exec sh -c 'for n; do basename "$n" .sh; done' sh {} +

or with a find that knows -execdir:

find . -type f -name '*.sh' \
    -execdir sh -c 'echo "${1%.sh}"' sh {} \;

(which is slightly less efficient as it's calling sh -c once per found file).

That is, find all regular files under the current directory whose names end with .sh. Pass these names (including path) to a subshell that iterates over the found names, calling basename for each to delete both the path and the extension from the name.


I wouldn't call this a "filter" as it doesn't actually filter anything, unless you call parsing out the base name from the complete path a "filter", or excluding directory names for things that are not files with the specified file name suffix.

A filter is usually something that reads data in at one end, transforms it, and spits something out at the other end (possibly feeding into another transformation).

Not the answer you're looking for? Browse other questions tagged or ask your own question.