I have a script which at one point does the following:
for src in $(find -H "$ROOT_DIR" -maxdepth 5 -name '*.test' -not -path '*.git*')
do
fixed_filename=$(echo "$(basename "${src%.*}")" | sed 's/-test//')
Basically, I have files called thing-test.js.test
When looping through I'd like to end up with the filename being thing.js
Eventually then I'll create the full path to the file using path="$ROOT_DIR"/"$fixed_filename"
The above seems to work, but it's definitely not correct - I'm an avid user of shellcheck and it tells me there's a useless echo (I agree) and to attempt ${variable//search/replace}
if possible.
Would appreciate some help on cleaning up the above.
Edit:
The basic gist of what I'm trying to do is:
I'm trying to recursively search through every file in a directory following a particular file name pattern e.g. file-test.js.test
and inside of these files are placeholder variables e.g. REPLACEME
I want to find all these files, and one-by-one replace REPLACEME
with a user supplied string from a read call inside of the bash script, and while I'm there I'd like to change the filename to file.js
e.g. remove -test
and .test
sed
andbasename
for this job, shell parameter expansion alone can do it. – don_crissti May 10 '17 at 18:52file-test.js.test
and inside of these files are placeholder variables e.g.REPLACEME
I want to find all these files, and one-by-one replace REPLACEME with a user supplied string from aread
call inside of the bash script, and while I'm there I'd like to change the filename tofile.js
e.g. remove-test
and.test
– Sudoscience May 10 '17 at 19:22For now, all of these files will follow the same pattern (
– Sudoscience May 10 '17 at 19:28filename-test.js.test
) but I'm probably going to be extending the script to support other dash separations e.g.filename-X.js.test
since some of those will be present too in the future but for now I was just concentrating on the originals