0

This question is related to Bash. The following is working in terminal:

url="http://user:pw@example.com:80/"
echo $url | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'

Terminal output: example.com

How to fix the following?

domain=$($url | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/') # not working
echo $domain
Alfred.37
  • 204
  • 1
  • 5
  • 23
  • 1
    you forgot echo in domain=$(echo "$url" | ...); and please do not duplicate your question of https://unix.stackexchange.com/q/624145/72456 – αғsнιη Dec 12 '20 at 19:32
  • @ αғsнιη THX. That works: domain=$(echo "$url" | sed -e 's/[^/]//([^@]@)?([^:/])./\2/'); echo $domain – Alfred.37 Dec 12 '20 at 20:46
  • @ roaima THX. I checked the linked source before submitting my question. A I didnt successfull tu adapt the solution from follow, for my question: https://unix.stackexchange.com/questions/16024/how-can-i-assign-the-output-of-a-command-to-a-shell-variable – Alfred.37 Dec 12 '20 at 20:49

1 Answers1

0

The left side of the pipe has to be a valid shell command that produces output to stdout. In bash you can also use <<< like that:

domain=$(sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/' <<< "$url")