Bash stdin到zip命令而不是提示符

Bash stdin到zip命令而不是提示符,bash,unix,terminal,zip,stdin,Bash,Unix,Terminal,Zip,Stdin,想用密码保护我的ZIP存档 使用以下内容创建存档: zip -er archivename.zip file 得到这个: Enter password: Verify password: 一切正常,但我有一个带有密码的变量,需要将此密码发送到zip。尝试过这样的论点,但失败了 echo "$1"| zip -er archivename.zip file 在bash中可能吗?由于zip实用程序不支持stdin -P password --password password

想用密码保护我的ZIP存档

使用以下内容创建存档:

zip -er archivename.zip file
得到这个:

Enter password: 
Verify password: 
一切正常,但我有一个带有密码的变量,需要将此密码发送到
zip
。尝试过这样的论点,但失败了

echo "$1"| zip -er archivename.zip file

在bash中可能吗?由于zip实用程序不支持stdin

-P password
--password password
       Use password to encrypt zipfile entries (if any).  THIS IS INSECURE!  Many multi-user operating systems  provide  ways
       for any user to see the current command line of any other user; even on stand-alone systems there is always the threat
       of over-the-shoulder peeking.  Storing the plaintext password as part of a command line in an automated script is even
       worse.   Whenever  possible, use the non-echoing, interactive prompt to enter passwords.  (And where security is truly
       important, use strong encryption such as Pretty Good Privacy instead of the relatively weak standard  encryption  pro‐
       vided by zipfile utilities.)
编辑:如果这对您不安全,请使用此简单的
expect
脚本:

#!/usr/bin/expect -f

set prompt {$ }
set password "secret"

#spawn the command
spawn zip -er archivename.zip file

# Look for passwod prompt (twice)
expect "*?assword:*"
send "$password\r"

expect "*?assword:*"
send "$password\r"
读这个人 对于不安全的解决方案,请使用
-p

-p |--密码密码使用密码加密zipfile条目(如果有)这是不安全的

用户交互 -e |——加密使用终端上输入的密码对zip存档的内容进行加密,以响应提示