我正在检查我的主题的更新脚本
我有 2 个文本文件。第一个称为“current.txt”并包含当前版本。4.1.1
该文本文件中有字符串。
第二个称为“latest.txt”并包含最新版本。4.2
此文本文件中有字符串。
所以这是代码
echo "Checking update";
x=$(cat ./current.txt)
y=$(cat ./latest.txt)
if [ "$x" -eq "$y" ]
then
echo There is version $y update
else
echo Version $x is the latest version
fi
Run Code Online (Sandbox Code Playgroud)
这意味着如果 current.txt 与 latest.txt 不同,那么它会说“有 4.2 版更新”。如果不是,它会说“版本 4.1.1 是最新版本”
但是当我尝试运行它时。我收到这个错误
Checking update
./test.sh: line 4: [: 4.1.1: integer expression expected
Version 4.1.1 is the latest version
Run Code Online (Sandbox Code Playgroud)
那么我做错了什么?
我正在为我的主题制作一个具有 2 个功能的工具脚本:检查更新,重新安装主题
所以这是选择菜单的代码:
PS3='Choose an option: '
options=("Check for update" "Reinstall theme")
select opt in "${options[@]}"
do
case $opt in
"Check for update")
echo "Checking update"
;;
"Reinstall theme")
echo "Reinstalling"
;;
*) echo invalid option;;
esac
done
Run Code Online (Sandbox Code Playgroud)
运行时显示如下
1) Check for update
2) Reinstall theme
Choose an option:
Run Code Online (Sandbox Code Playgroud)
我输入 1 并回车,执行检查更新命令
问题是当它完成执行脚本时,它重新显示“选择一个选项:”而不是菜单。所以它可以让用户在没有菜单的情况下难以选择(特别是在一个很长的脚本之后)
1) Check for update
2) Reinstall theme
Choose an option: 1
Checking update
Choose an option:
Run Code Online (Sandbox Code Playgroud)
那么如何在执行选项后重新显示菜单
我为我的主题制作工具脚本有 6 个选项:1)检查主题更新 2)重新安装主题 3)安装字体 4)安装壁纸 5)检查工具更新 6)退出
这是代码
clear
echo "==========================="
echo "Tool for theme"
echo "==========================="
function check_update {
echo "checking theme update"
}
function reinstall_theme {
echo "Reinstalling"
echo "==========================="
}
function font {
echo "Installing font"
}
function wall {
echo "Installing wallpaper"
}
function check_update_tool {
echo "Checking tool update"
}
all_done=0
while (( !all_done )); do
options=("Check theme update" "Reinstall theme" "Install font" "Install wallpaper" "Check tool update" "Quit")
echo "Choose an option: " …
Run Code Online (Sandbox Code Playgroud)