Posted By

vikiyou on 06/05/13


Tagged


Versions (?)

_getdomainnameonly


 / Published in: Bash
 

Get domain name and remove protocol part, username:password and other parts from url

  1. # Name: _getdomainnameonly
  2. # Arg: Url/domain/ip
  3. # Returns: Only domain name
  4. # Purpose: Get domain name and remove protocol part, username:password and other parts from url
  5. _getdomainnameonly(){
  6. # get url
  7. local h="$1"
  8. # upper to lowercase
  9. local f="${h,,}"
  10. # remove protocol part of hostname
  11. f="${f#http://}"
  12. f="${f#https://}"
  13. f="${f#ftp://}"
  14. f="${f#scp://}"
  15. f="${f#scp://}"
  16. f="${f#sftp://}"
  17. # Remove username and/or username:password part of hostname
  18. f="${f#*:*@}"
  19. f="${f#*@}"
  20. # remove all /foo/xyz.html*
  21. f=${f%%/*}
  22. # show domain name only
  23. echo "$f"
  24. }

Report this snippet  

You need to login to post a comment.