Created
June 17, 2020 05:21
-
-
Save myclau/9632fc83bd7cf2e2f7876f9a62fbd359 to your computer and use it in GitHub Desktop.
find_relative_path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#powershell | |
# just put the uri without domain in to this variable | |
$gitremoteUri="xxxx/xxxxxt/xxx" | |
$relativeRootPath="" | |
$gitremoteTreeLevel=$gitremoteUri.split('/').length | |
for ($i=0; $i -lt $gitremoteTreeLevel ; $i++){ | |
$relativeRootPath+="../" | |
} | |
# this result of relativeRootPath will be ../../../ | |
$relativeRootPath | |
#bash | |
#!/bin/bash | |
gitremoteUri="xxxx/xxxxxt/xxx" | |
delimiter='/' | |
s=$gitremoteUri$delimiter | |
array=(); | |
while [[ $s ]]; do | |
array+=( "${s%%"$delimiter"*}" ); | |
s=${s#*"$delimiter"}; | |
done; | |
relativeRootPath="" | |
for (( i=0; i<=${#delimiter[@]}; i++ )) | |
do | |
relativeRootPath+="../" | |
done | |
# this result of relativeRootPath will be ../../../ | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment