为什么我的 bash 脚本在没有我询问的情况下就回答提示?

为什么我的 bash 脚本在没有我询问的情况下就回答提示?

我想卸载软件包并在用户模式下重新安装它们。我有一个用 手动编辑的列表flatpak list,其中该行的第一个单词是包的完整名称。

我可以制作一个打印名称的脚本,它们是正确的。我可以flatpak uninstall对这些名称手动执行并且它可以工作。

但是,当我运行以下循环时(为了清楚起见,我删除了安装部分),脚本没有给我选择并以否定的方式回答所有提示:

#!/bin/bash
while read line
do
app_name=$(echo "$line" | awk '{print $1}')
flatpak uninstall --delete-data "$app_name"
done < flatpaklist.txt

这是我得到的输出:

        ID                                                 Branch           Op
 1.     io.github.Figma_Linux.figma_linux                  stable           r
 2.     io.github.Figma_Linux.figma_linux.Locale           stable           r
 3.     org.freedesktop.Platform.GL.default                20.08            r
 4.     org.freedesktop.Platform.Locale                    20.08            r
 5.     org.freedesktop.Platform.VAAPI.Intel               20.08            r
 6.     org.freedesktop.Platform                           20.08            r

Proceed with these changes to the system installation? [Y/n]: n
Similar installed refs found for ‘org.freedesktop.Platform’:

   1) runtime/org.freedesktop.Platform/x86_64/20.08 (system)
   2) runtime/org.freedesktop.Platform/x86_64/22.08 (system)
   3) All of the above

Which do you want to use (0 to abort)? [0-3]: 0
error: No ref chosen to resolve matches for ‘org.freedesktop.Platform’
Similar installed refs found for ‘org.freedesktop.Platform’:

   1) runtime/org.freedesktop.Platform/x86_64/20.08 (system)
   2) runtime/org.freedesktop.Platform/x86_64/22.08 (system)
   3) All of the above

Which do you want to use (0 to abort)? [0-3]: 0
error: No ref chosen to resolve matches for ‘org.freedesktop.Platform’
Similar installed refs found for ‘org.freedesktop.Platform.GL.default’:

   1) runtime/org.freedesktop.Platform.GL.default/x86_64/22.08-extra (system)
   2) runtime/org.freedesktop.Platform.GL.default/x86_64/22.08 (system)
   3) runtime/org.freedesktop.Platform.GL.default/x86_64/21.08 (system)
   4) runtime/org.freedesktop.Platform.GL.default/x86_64/20.08 (system)
   5) All of the above

如您所见,答案“n”或“0”已被输入。但这不是我的事,我别无选择。

我也尝试过yes | flatpak uninstall --delete-data "$app_name"。当需要数字时,它仍然自动回答“0”,当需要“是”或“否”时,它仍然自动回答“n”。

相关内容