This is an entirely trivial one-liner; for example:
rename_pieces smali/com/FOLDER/SUB-FOLDER smali/com/NEW/SUBNEW
...assuming, of course, that you run an appropriate function definition first. If you only want to rename SUB-FOLDER
, after creating NEW-NAME
should it not exist, that would look like:
rename_pieces() {
local old=$1 new=$2
[[ $new = */* ]] && mkdir -p -- "${new%/*}"
mv -T -- "$old" "$new"
}
...and this is much more likely to be the behavior you really do want than any other interpretation, insofar as it leaves contents of FOLDER
other than SUB-FOLDER
alone with its original name.
By contrast, if you really want to rename both directories, that gets a lot more interesting. If we have a guarantee that both source and destination are at the same depth, this might look something like:
log_or_run() {
if [[ $log_only ]]; then # just log what we would run
printf '%q ' "$@" >&2 # use printf %q to generate a safely-escaped version
printf '\n' >&2 # ...and terminate with a newline.
else
"$@" # actually run the command
fi
}
rename_pieces() {
local old=$1 new=$2 common
while [[ ${old%%/*} = "${new%%/*}" ]]; do
common+=/"${old%%/*}"
old=${old#*/}; new=${new#*/}
done
while [[ $old && $new ]]; do
log_or_run mv -T -- "${common#/}/${old%%/*}" "${common#/}/${new%%/*}"; echo
common+=/"${new%%/*}"
[[ $old = */* && $new = */* ]] || return
old=${old#*/}; new=${new#*/}
done
}
Whereafter:
log_only=1 rename_pieces smali/com/FOLDER/SUB-FOLDER smali/com/NEW/SUBNEW
...emits on output:
mv -T -- smali/com/FOLDER smali/com/NEW
mv -T -- smali/com/NEW/SUB-FOLDER smali/com/NEW/SUBNEW
...and doing likewise without log_only=1
actually runs those commands.