Below is a solution for the typical problem related to parsing urls:
url="http://sample.com/path/to/res?p1=1&p2=2" url_no_params=${url%%\?*} echo $url_no_params params=${url##*\?} echo $params host_and_path=${url##*\/\/} echo $host_and_path host=${host_and_path%%\/*} echo $hostThe above will result in:
$url="http://sample.com/path/to/res?p1=1&p2=2" $url_no_params=${url%%\?*} $echo $url_no_params http://sample.com/path/to/res $params=${url##*\?} $echo $params p1=1&p2=2 $host_and_path=${url##*\/\/} $echo $host_and_path sample.com/path/to/res?p1=1&p2=2 $host=${host_and_path%%\/*} $echo $host sample.com
No comments:
Post a Comment