如何从bash或脚本文件运行wget?

时间:2019-03-15 02:33:51

标签: bash url terminal wget

我正在尝试从脚本文件(sh)中运行以下 wget 命令及其参数,但该命令将无法运行。但是,如果我在终端或控制台上运行相同的命令,它将按预期运行。有人可以告诉我我在做什么错。

GetMyUrls.sh

URL="http://craigslist.com"
wget -q ${URL} -O - | tr "\t\r\n'" '   "' | grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' | sed -e 's/^.*"\([^"]\+\)".*$/\1/g' > myurls.txt

编辑: 如果我直接在终端中运行以下命令,则该命令有效,并且输出显示在代码下方。

wget -q http://craigslist.com -O - |     tr "\t\r\n'" '   "' |     grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' |     sed -e 's/^.*"\([^"]\+\)".*$/\1/g' > myurls.txt

输出:

baby-jesus@babyjesus-X501A1:~$ wget -q http://craigslist.com -O - |     tr       "\t\r\n'" '   "' |     grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:      [^"]\+"' |     sed -e 's/^.*"\([^"]\+\)".*$/\1/g'
https://post.craigslist.org/c/pit
https://accounts.craigslist.org/login/home
https://www.craigslist.org/about/sites
https://post.craigslist.org/c/pit
https://accounts.craigslist.org/login/home
https://www.craigslist.org/about/help/
https://www.craigslist.org/about/scams
https://www.craigslist.org/about/safety
https://www.craigslist.org/about/privacy.policy   
https://www.craigslist.org/about/help/system-status
https://www.craigslist.org/about/ 
https://www.craigslist.org/about/craigslist_is_hiring
https://www.craigslist.org/about/open_source
http://blog.craigslist.org/
https://www.craigslist.org/about/best/all/
https://www.youtube.com/user/craigslist
http://www.craigslistjoe.com/
http://craigconnects.org/
https://forums.craigslist.org/?areaID=33
https://forums.craigslist.org/?areaID=33&amp;forumID=5178
https://forums.craigslist.org/?areaID=33&amp;forumID=3232

我只想做完全一样的事情,但是从脚本文件开始,并通过在字符串的末尾添加> myurls.txt

将输出定向到文本文件。

0 个答案:

没有答案