3

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
Sharon
  • 101
  • 1
  • 5
  • 2
    C'mon, you ought to know by now that "does not function properly" is not a diagnosis... – Ignacio Vazquez-Abrams Jun 21 '11 at 18:41
  • 1
    Sorry, I don't read minds on Tuesday. You'll have to actually tell us what's not working. – cledoux Jun 21 '11 at 18:45
  • Sorry. If the script is run by double-clicking it then choosing run, it executes but will not save a file or load contents from an existing file. – Sharon Jun 21 '11 at 18:56
  • 2
    When you're in the terminal, you're cd'ing to a directory? (I'm guessing). How does the double-click run know which directory to be in? Also, you might want to add `set -vx` at the top to see debugging and trace info. Good luck! – shellter Jun 21 '11 at 19:12

1 Answers1

1

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.

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130