Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- url_parse() {
- sed -nre '
- /^(([^:]+):(\/{0,2}))?(([^:]+):([^@]+)@)?([^:\/]*)?:?([^/]+)?(.*)$/ {
- h
- s##U[scheme]="\1"#p;g
- s##U[user]="\5"#p;g
- s##U[pass]="\6"#p;g
- s##U[domain]="\7"#p;g
- s##U[port]="\8"#p;g
- s##U[path]="\9"#;s#/./#/#g;s#/+#/#g;p
- }' | tr '"' "'"
- }
- url_construct() {
- echo ${U[scheme]:-''}${U[user]}${U[pass]:+':'}${U[pass]}${U[user]:+'@'}${U[domain]:-''}${U[port]:+':'}${U[port]}${U[path]:-'/'}
- }
- declare -A U
- u1='https://UsErNaMe:My5tR0nGp4s5@domain.ru:8088//./dump.txt'
- u2='file:///home/krd/lulz.txt'
- echo "${u1}" | url_parse
- # output:
- # U[scheme]='https://'
- # U[user]='UsErNaMe'
- # U[pass]='My5tR0nGp4s5'
- # U[domain]='domain.ru'
- # U[port]='8088'
- # U[path]='/dump.txt'
- eval $(echo "${u1}" | url_parse)
- url_construct
- # output:
- # https://UsErNaMe:My5tR0nGp4s5@domain.ru:8088/dump.txt
- echo "${u2}" | url_parse
- # output:
- # U[scheme]='file://'
- # U[user]=''
- # U[pass]=''
- # U[domain]=''
- # U[port]=''
- # U[path]='/home/krd/lulz.txt'
- eval $(echo "${u2}" | url_parse)
- url_construct
- # output:
- # file:///home/krd/lulz.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement