在终端外部运行时Bash脚本不工作

在终端外部运行时Bash脚本不工作,bash,ubuntu,gnupg,zenity,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 fi

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

#!/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>和双击
env>来比较环境,然后使用
diff
或类似方法


您还可以(完成上述操作后)在脚本中从_terminal
获取
,查看它是否与终端环境一起工作。如其中一条评论所述,
set-vx
是您的朋友。

不是诊断…对不起,我星期二不读大脑。你必须告诉我们什么不起作用。对不起。如果脚本是通过双击它然后选择“运行”来运行的,它会执行,但不会保存文件或从现有文件加载内容。当你在终端中时,你正在将cd'刻录到一个目录?(我猜)。双击运行如何知道要在哪个目录中?此外,您可能希望在顶部添加
set-vx
,以查看调试和跟踪信息。祝您好运!