I have a script like this:
#!/bin/bash
REGEX='(www\.)?\w*\.\w*'
echo "$1" | grep -P -o $REGEX
DOMAIN="$1" | grep -P -o $REGEX
echo $DOMAIN
What I want to achieve is to get the domain from a full URL.
If I give as parameter the: http://example.com/
then I need the example.com
The first echo works.
How could I pass that expression into a variable? I need to pass later the DOMAIN
to a script.
echo | grep
in the variableDOMAIN
...DOMAIN=$(echo "$1" | grep -P -o $REGEX)
var=$(command)
is a pretty basic concept in (unix/linux) shell scripting; not really worthy of an answer; I would recommend reviewing the linked 'duplicates' for other, more efficient, methods of parsing a string; good luck