@@ -255,6 +255,50 @@ _bash_sh_load_env_files() {
255255 :
256256}
257257
258+ # replace bash.sh code-block for you.
259+ #
260+ # usage:
261+ #
262+ # your_ops_script="$somewhere/ops"
263+ # bashsh_file="$some-tmp-folder/bash.sh"
264+ # repl_bashsh_block "$your_ops_script" "$bashsh_file"
265+ #
266+ # this helper will upgrade bash.sh code-block between
267+ # "#### HZ Tail BEGIN #### v" and "#### HZ Tail END #### v"
268+ # with the newest source (specified in $bashsh_file)
269+ #
270+ # if the immediate files should be kept, specify the 3rd
271+ # arg to 0:
272+ #
273+ # repl_bashsh_block "$your_ops_script" "$bashsh_file" 0
274+ #
275+ repl_bashsh_block () {
276+ local CD=" $( cd $( dirname " $0 " ) && pwd) "
277+ local tgt_file=" ${1:- $CD / bin/ ops} "
278+ local bashsh_file=" ${2:- $CD / ../ ../ ../ ../ ops.work/ bash.sh-dev/ bash.sh/ bash.sh} "
279+ local no_keep_imm=" ${3:- 1} "
280+ local begin_str=" #### HZ Tail BEGIN #### v"
281+ local end_str=" #### HZ Tail END #### v"
282+ if [ -f " $bashsh_file " ]; then
283+ ls -la $bashsh_file
284+ # grep -E "${begin_str}"'(.*)'"${end_str}" $bashshfile >repl.1.log
285+ echo " sed -n '/${begin_str} /,/${end_str} /p' $bashsh_file >repl.1.log"
286+ eval " sed -n '/${begin_str} /,/${end_str} /p' $bashsh_file >repl.1.log"
287+ # sed '/begin_pattern/,/end_pattern/s/original_text/replacement_text/g' filename
288+ eval " sed '/${begin_str} /,/${end_str} /d' $tgt_file >repl.2.log"
289+ ls -la repl.* .log
290+ mv $tgt_file {,.bak}
291+ cat repl.2.log repl.1.log > $tgt_file
292+ tip " replaced ok. The differences between $tgt_file and $tgt_file .bak are:"
293+ (( $NO_DIFF )) && : || {
294+ if cmd_exists diff; then
295+ diff $tgt_file $tgt_file .bak
296+ fi
297+ }
298+ (( $no_keep_imm )) && rm repl.* .log $tgt_file .bak || :
299+ fi
300+ }
301+
258302# #######################################################
259303
260304# ### HZ Tail BEGIN #### v20251115 ####
0 commit comments