Bash Shell - Script to get user-chosen URL’s

Asked

Viewed 75 times

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

  • 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

  • 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/

  • 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

  • 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

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.