我已经为Windows和Linux编写了脚本,以在新用户的工作空间中设置所有来自我们服务器的git存储库。
我希望用户只需输入一次我们服务器的密码,将其存储在本地变量中,然后将该变量传递给每个git pull
命令,然后清除密码变量并退出。
如何在git pull
命令请求密码时输入密码?无论是Windows批处理文件还是Linux Shell脚本。
这是Linux脚本中的代码:
#!/bin/bash
echo "Enter password: "
read pswd
clear #No screen peaking
#This is repeated for each repo
location=folderName
mkdir $location
cd $location
git init
git remote add origin git@<server>:$location.git
git pull origin master
#Above prompts for password & is where I want to automatically input $pswd
我尝试过 SO 和其他地方推荐的各种方法,比如管道、从 .txt 文件读取等等。我希望不需要使用除了普通的 Windows 命令提示符和 Linux 终端命令之外的任何东西。并且由于这个脚本只是为了设置目的,我不需要像 ssh 代理那样安全地永久存储密码。
我正在运行 Windows 7 和 Ubuntu 12.10,但这个脚本是用来设置新用户的,所以最好能在大多数发行版上运行。
echo $PASSWORD | git pull
。 - TamaMcGlinn