0
Good night, I have a question about a bash shell script that will return the URL’s present in a Reddit page, that is, in a subreddit. What I managed so far was to return the URL’s that are on a page inserted in the code and I wanted that when I ran the program the user could write a word and the script would fetch the URL’s with that word in common. This is the code I have so far:
" wget -qO- https://www.reddit.com/r/todayilearned/ |grep -Eo "(http)://[a-zA-Z0-9./?=_-]*" | sort | uniq "
You can use read to capture the term and then use a grep to filter
#!/bin/bash

read -p "Informe um termo: " term;

wget -qO- https://www.reddit.com/r/todayilearned/ |grep -Eo "(http)://[a-zA-Z0-9./?=_-]*" | grep $term | sort | uniq
– Valdeir Psr
I tried it like this and after entering the term to research the program ends and does nothing. But what I really wanted was when I was at the command line and I did. /Reddit.sh, write the search word for example . /Reddit.sh linux
– user81007
This is the result I want... "$ . /Reddit.sh linux" and when that enter appeared the URL’s http://blog.linuxmint.com/? p=3001? http://blog.linuxmint.com/? p=2994&_utm_source=1-2-2 http://www.shashlik.io/news/2016/02/18/shalik-0-9-0-kubuntu-package/
– user81007
To use arguments just use ** $1 ** to capture the first term, ** $2 ** to capture the second term (if any) and so on. That is, just replace the read by
term=$1
– Valdeir Psr
It still doesn’t work, there must be something wrong, the code is now like this: #!/bin/bash term=$1 wget -qo- https://www.reddit.com |grep -Eo "(http|https)://[a-za-Z0-9. /?= _-]*" | grep $term | Sort | Uniq
– user81007