HTTP文字列に資格情報を挿入しますか?

HTTP文字列に資格情報を挿入しますか?

git内のgit資格情報ファイルを正しく入力できるように、ユーザー資格情報をHTTP文字列に挿入する必要があります~/.git-credentials

始める必要がある3つの環境変数は次のとおりです。

user="someUser"
pass="somePass"
uri="http://sometld.org/path/repo.git"

これを見てみましたが、非標準パス()ではなくawkGithubスタイルの複製パス()でのみ機能します。https://github.com/org/repo.githttps://git.private.org/scm/~user/path/repo.git

proto=$(echo $uri | awk -F"/" '{print $1}')
domain=$(echo $uri | awk -F"/" '{print $3}')
repo_path=$(echo $uri | awk -F"/" '{print $4}')
repo_name=$(echo $uri | awk -F"/" '{print $5}')
echo "$proto//$user:$pass@$domain/$repo_path/$repo_name"
# http://someUser:[email protected]/path/repo.git

私のファイルを埋めるためにHTTP文字列にユーザー名とパスワードを挿入する~/.git-credentials最も簡単で簡単な方法は何ですか?

ベストアンサー1

$ sed -e "s^//^//$user:$pass@^" <<<$uri
http://someUser:[email protected]/path/repo.git

これは文字列内で置き換えられ、//どこでも使用できます。//$user:$pass@$uri

特にBashでは:

$ echo ${uri/\/\////$user:$pass@}
http://someUser:[email protected]/path/repo.git

同じ代替操作を実行します。- これがまさにそれなのですが${variable/pattern/replacement}、ここでは区切り記号を変更できないため、パターンからスラッシュをエスケープする必要があります。

おすすめ記事