Quote:
Originally Posted by cfajohnson
(Code reformatted for legibility)
That will fail if any filenames contain spaces. Pipe the output of find into a loop:
Code:
find . -name "*.BEFORE_DISASTER_RECOVERY" |
while read file
do
: do whatever
done
(And your script will be more legible if you use a meaningful variable name for the loop.)
There is no need for either external command, dirname or basename. The Unix shell can do it internally:
Code:
dir_name=${file%/*}
file_name=${file##*/}
Both the cd and mv will fail if $dir_name contains spaces. Quote variable references:
Code:
cd "$dir_name"
mv "$file_name"
All you need is:
Code:
find . -name "*.BEFORE_DISASTER_RECOVERY" |
while read file
do
mv "$file" "$file%.BEFORE_DISASTER_RECOVERY}"
done
|
I definitely knew I was new to linux scripting, but never realized I was that bad, lol.
Anyways, I think you misunderstood or had a typo, I don't want to add that to my file, I want to remove it.
I have files named:
startServerABC.BEFORE_DISASTER_RECOVERY
or
startServer.sh.BEFORE_DISASTER_RECOVERY
I need to remove the .BEFORE_DISASTER_RECOVERY from the file name, to be left with
startServerABC or startServer.sh