Estou usando uma caixa de diálogo para modificar um único valor em um arquivo:
#!/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
Mas executando este script eu chego test.md
nestes valores:
# 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
Como posso remover quaisquer caracteres de controle UPSTREAM_VERSION
anteriores echo
a ele no arquivo?