我正在编写我的第一个 bash 脚本。我正在让它安装我在 GitHub 上的所有存储库。
warpInLocations=("git@github.com:acc/toolkit.git" "git@github.com:acc/sms.git" "git@github.com:acc/boogle.git" "git@github.com:acc/cairo.git")
Run Code Online (Sandbox Code Playgroud)
当我安装它们时,它们就是它们。
echo "warping in toolkit, sms, boogle and cairo"
for repo in "${warpInLocations[@]}"
do
warpInDir=$(echo ${warpToLocation}${repo} | cut -d'.' -f1)
if [ -d "$warpToLocation"]; then
echo "somethings in the way.. $warpInDir all ready exists"
else
git clone $repo $warpInDir
fi
done
Run Code Online (Sandbox Code Playgroud)
此处的这一行,我希望它为我提供一个名为toolkit
or的文件夹sms
,因此在位置扭曲之后/
和之前.
,但它正在选择git@github
。我猜,因为它在.
.
我怎样才能让它在回购中选择名称?
您需要分两步进行:
dir=git@github.com:acc/toolkit.git
dir=${dir#*/} # Remove everything up to /
dir=${dir%.*} # Remove everything from the .
Run Code Online (Sandbox Code Playgroud)
小智 7
dir=$(basename git@github.com:acc/toolkit.git .git)
Run Code Online (Sandbox Code Playgroud)
将设置$dir
为toolkit
.
同样有用的是dirname
命令。
归档时间: |
|
查看次数: |
390 次 |
最近记录: |