we tried to find the username of the mercury URL:
default = ssh://someone@acme.com//srv/hg/repo
Suppose there is always a username, I came up with:
tmp=${a#*//} user=${tmp%%@*}
Is there a way to do this on a single line?
Assuming your string has a variable like this:
url='default = ssh://someone@acme.com//srv/hg/repo'
You can do:
[[ $url =~ //([^@]*)@ ]]
Then your username is here:
echo ${BASH_REMATCH[1]}
This works in Bash versions 3.2 and higher.
To a large extent, you need more than one application or access external tools. I think sed is best suited for this.
sed -r -e 's|.*://(.*)@.*|\1|' <<< "$default"
bash. , sed.
mercurial, url,
echo 'ssh://someone@acme.com/srv/hg/repo' |grep -E --only-matching '\w+@' |cut --delimiter=\@ -f 1
, , .
Source: https://habr.com/ru/post/1776284/More articles:Rails 3 Username-Bound Routing Resources - ruby-on-railsoutput to a new terminal - cПроблема с часовым поясом по умолчанию Coldfusion 9 - timezoneOpening a terminal from Linux Makefile - c ++Интеграция PythonTidy в Coda? - pythonHow to speed up this double cycle? - performanceLinq to Entities - NotSupportedException - dynamic type - string.Format - c #How can I mix form authentication and Windows authentication in MVC 2 in IIS 7.5? - model-view-controllerHow to distinguish between different encodings / serialization / etc? - typesVCBuild task in MSBuild - change output path - msbuildAll Articles