Make flat_cp tool portable to systems without GNU sed

This commit is contained in:
Fedor A. Fetisov 2014-05-12 18:01:13 +04:00
parent 1c9430286c
commit bac1404cf1

View File

@ -23,17 +23,17 @@
# #
source_file=$1 source_file=$1
cut_from=$(sed -r "s/\/+$//" <<< "$3") cut_from=$(sed "s/\/\{1,\}$//" <<< "$3")
if [ $cut_from ] if [ $cut_from ]
then then
cut_from=$(sed -r "s/\//\\\\\//g" <<< "$cut_from") cut_from=$(sed "s/\//\\\\\//g" <<< "$cut_from")
target_file_name=$(sed -r "s/^(.*)$cut_from\/(.*)$/\2/" <<< "$source_file") target_file_name=$(sed "s/^\(.*\)$cut_from\/\(.*\)$/\2/" <<< "$source_file")
else else
target_file_name=$source_file target_file_name=$source_file
fi fi
target_file_name=$(sed -r "s/\//_/g" <<< "$target_file_name") target_file_name=$(sed "s/\//_/g" <<< "$target_file_name")
target_file=$(sed -r "s/\/?$//" <<< "$2")"/"$target_file_name target_file=$(sed "s/\/\{0,1\}$//" <<< "$2")"/"$target_file_name
cp $source_file $target_file cp $source_file $target_file