Extracting substring from environment variable

You can use parameter expansion, which is available in any POSIX compliant shell.

$ export FOO=http://unix.stackexchange.com/questions/ask
$ tmp="${FOO#*//}" # remove http://
$ echo "${tmp%%/*}" # remove everything after the first /
unix.stackexchange.com

A more reliable, but uglier method would be to use an actual URL parser. Here is an example for python:

$ echo "$FOO" | python -c 'import urlparse; import sys;  print urlparse.urlparse(sys.stdin.read()).netloc' 
unix.stackexchange.com

If the URLs all follow this pattern I have this short and ugly hack for you:

echo "$FOO" | cut -d / -f 3

Can be done also with regex groups:

$ a="http://unix.stackexchange.com/questions/ask"
$ perl -pe 's|(.*//)(.*?)(/.*)|\2|' <<<"$a"
unix.stackexchange.com