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

发布于 2024-11-16 07:14:04 字数 885 浏览 2 评论 0原文

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

#!/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

This script does not function properly when launched graphically (by double clicking script icon and selecting run), however, runs just fine if called from the terminal; will not save a file or load contents from an existing file. Please help! Thank you.

#!/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-11-23 07:14:04

导致该错误的可能原因是,通过交互式 shell 执行(从而获取 .bashrc)和双击(非交互,而不是获取 .bashrc< /code>

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

你也可以(做完之后上面)在脚本中使用 source from_terminal 来查看它是否适用于终端环境,如评论之一所述,set -vx 是您的朋友。

A probable cause for the error is that you have different environments when executing via an interactive shell (thus sourcing your .bashrc) and double-clicking (non-interactive, and not sourcing .bashrc

You can compare the environments by doing an env > from_terminal vs. env > double_click and then using diff or something similar.

You could also (after doing the above) source from_terminal in your script to see if it works with the terminal environment. As stated in one of the comments, set -vx is your friend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文