I am new to shellscripting and I try to automate & guify some jobs.
Suppose I have a variable the stores a passwd and an application like "gpg" or "zip" to run from withn the script.
how do I pass that passwd (the content of the variable) to the application being called?
eg.
#/bin/bash
passwd=$1
gpg -d ~/thegpgfile.gpg
running this my terminal sits there waiting for me to enter a passwd. How do I automaticaly use the $passwd so the script continues execution without me interacting?
thank you in advance
p.s. excuse the english. its not me native language
Whereas a kludge using just shell scripts is as follows:
$
$ file testfile.*
testfile.gpg: GPG encrypted data
$
$ cat decrypt.sh
#!/bin/bash
gpg --output testfile.txt --decrypt testfile.gpg
$
$ cat passphrase.txt
disneyland
$
$ . decrypt.sh <passphrase.txt
You need a passphrase to unlock the secret key for
user: "Alice"
2048-bit ELG-E key, ID 46972146, created 2009-07-18 (main key ID 53FD32A9)
gpg: encrypted with 2048-bit ELG-E key, ID 46972146, created 2009-07-18
"Alice"
$
$ file testfile.*
testfile.gpg: GPG encrypted data
testfile.txt: ASCII text
$
$ cat testfile.txt
this is a test file
that I'd like to encrypt/decrypt
using gpg
$
$
I real dont want to use expect because of portability issues.
No offense...but I realy dont undersatnd your example...I see what you are doing...but what are you trying to say?
There isn't one well defined way of passing a password to a program. Some you can echo to, others won't allow that (ssh for example). gpg only allows it with the --passphrase-fd option.
As for your example: the file utility works on files. There's no option to read from a pipe. Better save the content to a temporary file, run file on it, and then read the content back into a variable with cat (or any other mechanism your shell might provide)