小编sup*_*anh的帖子

如何制作“按任意键继续”

我正在制作一个脚本来安装我的主题,安装完成后会出现变更日志,并且会有“按任意键继续”,以便用户阅读变更日志后按任意键继续

bash

266
推荐指数
3
解决办法
27万
查看次数

Bash - 预期的整数表达式

我正在检查我的主题的更新脚本

我有 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)

那么我做错了什么?

string shell-script test numeric-data

15
推荐指数
2
解决办法
7万
查看次数

bash - 选择并执行选择后如何重新显示选择菜单

我正在为我的主题制作一个具有 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)

那么如何在执行选项后重新显示菜单

bash select

8
推荐指数
1
解决办法
2万
查看次数

Bash - 如何在 1 行中进行每个菜单选择,而不是在 1 行中进行多个选择

我为我的主题制作工具脚本有 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)

bash

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×3

numeric-data ×1

select ×1

shell-script ×1

string ×1

test ×1