Bash 脚本在终端外运行时不起作用

标签 bash ubuntu gnupg zenity

此脚本在以图形方式启动时无法正常运行(通过双击脚本图标并选择运行),但是如果从终端调用则运行良好;不会保存文件或从现有文件加载内容。请帮忙!谢谢。

#!/bin/bash

# This script provides a simple and secure messaging system for users not
# familiar with gpg or using the terminal. The idea is to keep sensitive
# plaintext files off one's computer.

zenity --question --text="Select operation:" --ok-label="Compose" --cancel-label="Read"
if [[ $? == 0 ]]; then
    usr=$(zenity --entry --text="Sender Key ID:")
    rec=$(zenity --entry --text="Recipient Key ID:")
    pwd=$(zenity --password)
    outfile=$(zenity --file-selection --save --confirm-overwrite)
    zenity --text-info --editable | gpg -aseu $usr -r $rec --passphrase $pwd --cipher-algo AES256 -o $outfile
else
    infile=$(zenity --file-selection)
    pwd=$(zenity --password)
    gpg -d --passphrase $pwd $infile | zenity --text-info --height=600 --width=800
fi

最佳答案

错误的一个可能原因是您在通过交互式 shell 执行时有不同的环境(因此采购您的 .bashrc)和双击(非交互式,而不是采购 .bashrc

您可以通过执行 env > from_terminalenv > double_click 然后使用 diff 或类似的东西来比较环境。

您还可以(在执行上述操作后)在脚本中获取 from_terminal 以查看它是否适用于终端环境。正如其中一条评论所述,set -vx 是您的 friend 。

关于Bash 脚本在终端外运行时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430311/

相关文章:

linux - Debian 和 Win7、Ubuntu 上的 OpenGL 阴影体积差异

bash - 根据分隔符拆分文件,然后加入单独的行

arrays - 如何在 Bash 中像时尚的 zipper 一样合并两个数组?

git GIT_WORK_TREE post-receive hook deployment remote

bash - Python - 解析为相对于脚本文件的绝对路径

ruby - 无法在 ubuntu 11.10 64 位上安装 rhc openshift 客户端

python - 如何在 venv 中运行 Python 脚本?

bash:使用 expect 来自动化 GPG 签名

Scala解密OpenPGP(GPG)加密文件

security - 非对称 key 容器的相互转换(例如 : X. 509、PGP、OpenSSH)