I have a messy script which should get the name of the site (like https://google.com/etc
):
#!/bin/bash ARTIST=$(echo "$@" | grep -oP 'https:\\/\\/\\K.+?(?=.com)' | sed -e "s/\b\(.\)/\u\1/g") echo $(echo "$@" | grep -oP 'https:\\/\\/\\K.+?(?=.com)' | sed -e "s/\b\(.\)/\u\1/g") echo "$ARTIST" echo "$@"
And for some reason, $(...)
doesn't return anything while running outside of the script works fine.
$ ./test.sh https://nothing.bandcamp.com/music https://nothing.bandcamp.com/music
Expected behavior:
$ echo "https://nothing.bandcamp.com/music" | grep -oP 'https:\\/\\/\\K.+?(?=.com)' | sed -e "s/\b\(.\)/\u\1/g" Nothing.Bandcamp
What am I doing wrong?
echo https://nothing.bandcamp.com/music | grep -oP 'https:\\/\\/\\K.+?(?=.com)'
returns nothing, I just tested it, I'm no expert on regular expressions, so I will leave this question to others. Cheers.