I am using a dialog in order to modify a single value into a file:
#!/usr/bin/env bash
prompt_and_save() {
local file=$1
local message=$2
local value=""
# Check if file exists and read value
if [ -f "$file" ]; then
value=$(cat "$file")
fi
# Prompt user with dialog
value=$(dialog --inputbox "$message" 8 50 "$value" 3>&1 1>&2 2>&3)
# Save the value if not empty
if [ ! -z "$value" ]; then
echo "$value" > "$file"
fi
clear
# Return the value
echo "$value"
}
UPSTREAM_VERSION=$(prompt_and_save "VERSION" "Bump the version (or keep it the same)")
clear
NEW_ENTRY="# Version $UPSTREAM_VERSION $DATE"
RELEASE_NOTES=$(cat RELEASE_NOTES)
echo -e "$NEW_ENTRY\n${RELEASE_NOTES}" > test.md
But running this script I get these values in test.md
:
# Version ^[[H^[[2J^[[3J0.2.0
1. Split codebase into multiple files.
2. Use a seperate version file and define built version upon compile.
4. [BUGFIX] If input file is same as output file copy input file into a temporary one.
5. Improved Documentation
6. [BUGFIX] Out of bounds argument parsing
7. [BUGFIX] Values should not be an Argument
How can I remove any control characters from UPSTREAM_VERSION
before echo
it into the file?
Asked by Dimitrios Desyllas
(1301 rep)
Mar 27, 2025, 07:53 PM
Last activity: Apr 1, 2025, 08:12 AM
Last activity: Apr 1, 2025, 08:12 AM