# shellcheck shell=bash # Version ID Block (comment-only -- NOT executable). Relies on +k filetype # modifier. This is a sourced library; a real 'declare' here would clobber # the sourcing script's own $Version (confirmed: they share global scope). # show_versions() greps this line's text directly; it is never evaluated. # VersionID='$Id: //p4-sdp/main/Server/Unix/p4/common/lib/latest_checkpoint.lib#1 $ $Change: 33433 $' # Function to get latest checkpoint MD5 by journal number get_latest_checkpoint_md5() { local checkpoint_dir="$1" local latest_md5="" local max_journal=0 # Use glob with nullglob to handle no matches gracefully shopt -s nullglob for md5_file in "${checkpoint_dir}"/checkpoint*.md5; do # Extract journal number from filename if [[ $(basename "$md5_file") =~ checkpoint\.ckp\.([0-9]+)\.md5$ ]]; then journal_num="${BASH_REMATCH[1]}" # Remove leading zeros for numeric comparison journal_num=$((10#$journal_num)) if (( journal_num > max_journal )); then max_journal=$journal_num latest_md5="$md5_file" fi fi done shopt -u nullglob echo "$latest_md5" } # Sample Usage: # LatestCheckpointMD5=$(get_latest_checkpoint_md5 "${ShowCheckpoints[i]}")