此脚本在以图形方式启动时无法正常运行(通过双击脚本图标并选择运行),但是如果从终端调用则运行良好;不会保存文件或从现有文件加载内容。请帮忙!谢谢。
#!/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_terminal
与 env > double_click
然后使用 diff
或类似的东西来比较环境。
您还可以(在执行上述操作后)在脚本中获取 from_terminal
以查看它是否适用于终端环境。正如其中一条评论所述,set -vx
是您的 friend 。
关于Bash 脚本在终端外运行时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430311/