我正在使用对话框来将单个值修改到文件中:
#!/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
但运行这个脚本我得到了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
我怎样才能从文件中删除它UPSTREAM_VERSION
之前的所有控制字符?echo