Question: I create a `zip` file using `zip` which includes several files and directories, named `test.upd`. Now I want to use `expect` to automatically handle the password encryption. Here are two bash scripts, both do not work:

```
!/bin/bash

MYPWD="mypassword"

expect -c '
    spawn zipcloak test.upd
    expect {
       "*Enter password*" { send "'"$MYPWD"'\r"
                                   exp_continue
                                  }
       "*Verify password*" { send "'"$MYPWD"'\r"
                                      exp_continue
                                    }
    }'

```

and this file: 

```
!/bin/bash
MYPWD="mypassword"

expect -c '
    spawn zipcloak test.upd
    expect "*Enter password*" 
    send "'"$MYPWD"'\r"
    expect "*Verify password*" 
    send "'"$MYPWD"'\r"

    }'

```

I also tried to create an `expect` script directly: 

```
#!/usr/bin/expect -f

spawn zipcloak test.upd
expect "*Enter password*" 
send "password\r"
expect "*Verify password*" 
send "password\r"

```

All scripts seem to send correctly the first password request, but it looks like the text for the second password entry is never asked. How can I do it right?

Constraints: 

* I have to use `zipcloak` (NOT `zip`)
* I want to use `expect` to automatically set the password.

Remarks: 

* I have used the correct script
* Each time, when using the first script, an empty file starting with `zi` is created in the directory, like `ziSvbYhy` or `zi3gzEQ4`.

Answer: 
It is my interpretation that the answers from Alex and ctrl-alt-delor don't properly wait for the zipcloak process to finish and therefore are prone to leave the zip file unencrypted (and leave a temporary file with a name such as `zimfwtpJ` behind). So their code work for small zip files but fail for larger ones.

Here is my solution:

```
#!/bin/bash
MYPWD="mypassword"

expect -c '
    set timeout -1
    spawn zipcloak test.upd
    expect "*Enter password*"
    send  "'"$MYPWD"'\r"
    expect "*Verify password*"
    send  "'"$MYPWD"'\r"
    expect eof
    '

```
The first example in the question worked for me.

```
!/bin/bash
MYPWD="mypassword"

expect -c '
     spawn zipcloak test.upd
     expect {
        "*Enter password*" { send "'"$MYPWD"'\r"
                               exp_continue
                              }
        "*Verify password*" { send "'"$MYPWD"'\r"
                                  exp_continue
                                }
}'

```

Though the second did not. Try it again, maybe you where running the wrong script. That often happens to me: I wonder why it does not work, but I am running the wrong script.