Hello, thank you very much for writing this script and taking the time to make it available. I have been looking for such a thing for quite a while now and lack of any of the skills to write it.
I have found and somewhat solved a compatibility issue with Mac OS. Sorry it's so long but I don't know how to do this properly and what can be left out. Also I have to admit I am extremely excited because I have never even halfway solved a programming(ish) problem in my whole life.
Summary
- Script does not run on mac OS because Mac OS has bash v 3.2 only.
- How to install bash 5 in Mac OS
- A way to edit the .sh file so the correct version of bash will be called
Describe the bug
I read in #1 that this script requires bash >v4. So I investigated and found out that even modern up to date versions of Mac OS are running bash 3.2 unless it has been manually upgraded. This has something to do with Apple being unable or unwilling to comply with the GPL requirements for v >4. See this SE thread among other discussions online.
Also of note (something I only learned recently despite being a regular if casual terminal user for many years) that zsh has been the default shell in Mac OS for some time now. Probably because they didn't want to have an out of date shell for the rest of time.
To Reproduce
- download and run per instructions
$ ./fetchurls.sh
Fetch a list of unique URLs for a domain.
Enter the full domain URL ( https://example.com )
Domain URL: https://quotes.toscrape.com
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
Save file to directory
./fetchurls.sh: line 492: read: -i: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
usage: mkdir [-pv] [-m mode] directory ...
Save file as
./fetchurls.sh: line 505: read: -i: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
Exclude files with matching extensions
./fetchurls.sh: line 518: read: -i: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
Fetching URLs for
./fetchurls.sh: line 358: /.txt: Permission denied
^Cease wait... [ | ]
Environment
To verify bash version:
$ bash --version
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
and also
$ which bash
which bash
/bin/bash
Apparently this is where bash 3 lives. Bash 4 lives in /usr/local/bin/bash
Workaround
-
Install homebrew if not already.
-
Install up to date bash (version 5 at time of writing)
-
bash 3 will still be active and the Internet says better not to replace it completely in case for some reason you need it some day. The instructions I looked at all assumed you would like to make bash 5 you default shell. However I am happy with zsh so I was able to find this which I believe makes it default only when you call bash
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
So now if I run bash --version
or which bash
it still returns v 3 as originally. (The Internet said which
should return both, but it didn't, strangely.) However if I actually switch to bash (by inputting command bash
) and enter those commands it will report v5.
Even when I ran the script from the bash 5 prompt instead of zsh, I still got same errors. (If you are thinking "this guy doesn't know anything about shell scripting" you are correct.) However I changed the top from
to
and the script ran. But it was taking so long to run I thought it was hanging and wouldn't complete and that's when I noticed the original said shift
not bash
which is the only thing I've ever seen at the top of a script. So I went to find out what that means and after some dead ends I found something that sounds reasonable but I don't understand. By the time I had finished reading that page the script completed. It ran just fine without shift
.
I also tried running it with both shebangs (new word I learned today) included but the result was the same. I ran the script in interactive mode with all defaults so perhaps a problem will arise at a later date. I'm sure you already have a good idea of the answer to that question.
Someone who understands what is going on here would probably be able to find a better solution but this seems to work.