From 0ff85c7128f06961d3221b63b67f7daedf47f477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Mon, 12 Feb 2024 23:09:17 +0100 Subject: [PATCH] Refactor _f_last_updated --- qsgen2 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/qsgen2 b/qsgen2 index e5ee8da..927ee17 100755 --- a/qsgen2 +++ b/qsgen2 @@ -430,23 +430,26 @@ function _f_last_updated() { local debug=true fi - local file_path="${1}" + # local file_path="${1}" local upd_msg="Last updated ${today} by ${QSGEN} ${VERSION}" if ${debug}; then - _msg debug "_f_last_updated: Setting date and version in footer of file ${file_path}" + _msg debug "_f_last_updated: Setting date and version in footer of file ${1}" _msg debug "_f_last_updated: ${upd_msg}" fi # Read the file content into a variable - local content="$(<${file_path})" + local content="$(<${1})" # Perform the replacement content="${content//#updated/${upd_msg}}" - sed -i '' -e "s|#updated|${upd_msg}|" "${file_path}" - # Write the updated content back to the file - #print -r -- "$content" >| "${file_path}" + if [[ -f "${1}" ]]; then + sed -i -e "s|#updated|${upd_msg}|" "${1}" + else + _msg debug "_f_last_updated: File '${1}' not found." + fi + } function _file_to_lower() {