【问题标题】:give user input when writing a bash script [duplicate]在编写 bash 脚本时提供用户输入 [重复]
【发布时间】:2021-08-08 09:35:50
【问题描述】:

我正在运行一个 bash 脚本,它会自动克隆一个 git repo。在提供的 git repo 中进行更改,然后将这些更改推送到 github。现在,当我克隆 repo 时,它会询问我的用户名,但我没有知道如何在 bash 脚本中提供这些输入。为了获得特权,我把一些东西涂黑了。但我会向你解释其余的。我已经尝试过 git config 但它不起作用。有人可以帮我解决这个问题

#!/bin/bash
set -e
appName=$(echo xxxxx/xxxxx)
echo $appName
version=`echo "$BRANCH_NAME-$BUILD_NUMBER" | tr / -`
echo $version
imageName=$appName:$version
echo $imageName
git config --global user.name "xxxxxxxx"
git config --global user.email "xxxxxxxxxxx"
git config --global user.password "xxxxxxxxxxxxxx"
git clone https://github.com/xxxxx/xxxxx.git
cd qa-namespace/red/website-manager
sed -i "s|\(image[[:space:]]*:[[:space:]]*\)\(.*\)|\1'${imageName}'|"  input deployment.yaml
git add .
git commit -m "changed name of the branch"
git push

【问题讨论】:

  • 使用SSH key
  • 始终使用$() 而不是反引号。
  • appName=$(echo xxxxx/xxxxx) 最好写成appName=xxxx/xxxx
  • 请注意,标准 Git 的任何部分都不会使用或检查 user.password 设置。
  • @WilliamPursell 感谢您的建议,但我的问题是 git

标签: linux bash git shell github


【解决方案1】:

你应该把git clone https://github.com/xxxxx/xxxxx.git改成git clone https://<USER_NAME>:<USER_PASSWORD>@github.com/xxxxx/xxxxx.git

【讨论】:

  • 嗨安东尼奥,我的密码中有一个@,因此它显示此错误致命:无法访问'2019@github.com/xxxxxxx/xxxxx.git':无法解析主机:2019@github.com
  • 我建议您更改密码。
猜你喜欢
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2013-03-23
  • 1970-01-01
  • 2015-10-30
相关资源
最近更新 更多