bash - Change part of script file by sed or awk -


i'm trying write sed command change script automatically. script using apply sql patches database based on provided version of application. better understandings simplify script , source looks like

# before if [ "$branch" = "trunk" ]     apply_patch.sh 1.0     apply_patch.sh 2.0     apply_patch.sh trunk elif [ "$branch" = "2.0" ]     apply_patch.sh 1.0     apply_patch.sh 2.0 elif [ "$branch" = "1.0" ]     apply_patch.sh 1.0 fi # after 

based on 2 input arguments (current version , next version) need change script following

# before if [ "$branch" = "trunk" ]     apply_patch.sh 1.0     apply_patch.sh 2.0     apply_patch.sh 2.1     apply_patch.sh trunk elif [ "$branch" = "2.1" ]     apply_patch.sh 1.0     apply_patch.sh 2.0     apply_patch.sh 2.1 elif [ "$branch" = "2.0" ]     apply_patch.sh 1.0     apply_patch.sh 2.0 elif [ "$branch" = "1.0" ]     apply_patch.sh 1.0 fi # after 

sketch of how might rework logic
have check correct array syntax
stop repeating , rewriting
, add new element array when patching changes

ln -s trunk 99999 declare -a appver=( 1.0 2.0 2.1 99999)  patch in  ${appver[@]} ;   if [ ${branch} <= ${patch} ]        apply_patch.sh  ${patch}   fi done 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -