non-interactive scripting

Terrence Enger tenger-P1ovA8G34VBEfu+5ix1nRw at
Mon Sep 28 22:17:44 UTC 2009

On Mon, 2009-09-28 at 17:36 -0400, Darryl Moore wrote:
> Hey all,
> I did some googling to find out how to write non-interactive script for
> creating GPG keys. I found it and now I have the following in my script
> cat <<-EOF | gpg --batch --quick-random --no-tty --gen-key
> %echo Generating a standard key
> Key-Type: DSA
> Key-Length: 1024
> Subkey-Type: ELG-E
> Subkey-Length: 1024
> Name-Real:
> Name-Comment: $COMPANY
> Name-Email: $CONTACT_EMAIL
> Expire-Date: 0
> Passphrase: $PASSPHRASE
> # Do a commit here, so that we can later print "done" :-)
> %commit
> %echo done
> This all works, but there are a few things I can't figure out (and Mr.
> Google doesn't seem to be much help either. ).
> 1) what is with the minus sign between the double-less-than signs and
> the EOF? The code I found had it in, I'd expect it not to work with it
> there, but it does. Does it do anything?

Indeed it does:  with the dash before the EOF string, bash strips
leading tab characters from each line of the "here" document.  This lets
you push the data out to the right so that it does not hide the
indentation which shows the structure of your bash code.  I find this
feature really useful.

I have nothing to offer on your other two questions.


The Toronto Linux Users Group.      Meetings:
TLUG requests: Linux topics, No HTML, wrap text below 80 columns

More information about the Legacy mailing list