Goal: I'm trying to find all instances of *.clj
or *.cljs
files recursively within a directory, store them in a string variable (separated by new lines) and then transform them.
So if the following clj(s)
files are found within my directory dir1
:
/dir1/dir2/hello1.clj
/dir1/dir2/hello2.clj
/dir1/dir2/hello3.cljs
/dir1/dir2/hello4.clj
/dir1/dir2/hello5.cljs
And my transformation is, let's say, merely to return the basename of each of these strings:
/dir1/dir2/hello1.clj -> hello1.clj
/dir1/dir2/hello2.clj -> hello2.clj
/dir1/dir2/hello3.clj -> hello3.clj
/dir1/dir2/hello4.clj -> hello4.clj
/dir1/dir2/hello5.clj -> hello5.clj
Then how can I write a function f
such that
$ VAR=$(f dir1)
satisfies
$ echo "$VAR"
hello1.clj
hello2.clj
hello3.clj
hello4.clj
hello5.clj
?
Attempt:
I know that I can generate the .clj
and .cljs
files of a directory via
FOUND_FILES=$(find "dir1" -type f -regex ".*\.\(clj\|cljs\)")
and that I can use the basename
command to get the basename of a file. How to do the rest?
find
and-exec
a function... – don_crissti Mar 13 '16 at 15:46