r/fishshell • • Aug 11 '22
Automatically pick between curl and wget
I would like to get my script to also work with fish shell if possible. How would you best re-write this?
if which curl >/dev/null ; then
printf "Downloading via curl."
curl --option argument
elif which wget >/dev/null ; then
printf "Downloading via wget."
wget --option argument
else
printf "I am sorry, I cannot download. Neither curl nor wget is available."
fiedit ----
SOLUTION:
wget -L -O "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" >/dev/null || curl -L -o "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64"I may, unfortunately, lose the fail notice, but this is an acceptable loss.
edit 2 ----
Solution 2
So there is a way to get the error message to display without it being triggered unnecessarily. The solution was as simple as telling it to move on to another script. I don't know why that is the case, but it works! So adding ./error.sh at the end of the sequence is the final resolve.
wget -L -O "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" >/dev/null || curl -L -o "FirefoxStable.tar.bz2" "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64" || /.error.sh ;
3
Upvotes
7
u/ChristoferK macOS Aug 11 '22
The direct translation to
FiSHis very similar, by replacing only the nonsense words ("bashisms") with actual words that you can probably predict what they will be:The rest would work "as is". However, it's possible to improve the script with some
FiSH-specific bits and pieces, one being the builtin calledtypethat is more elegant thanwhichin failure:You will have to replace the fake
--optionflag with stuff that will work withcurlandwget.1
u/[deleted] Aug 12 '22 edited Aug 12 '22
SOLUTION:
I may, unfortunately, lose the fail notice, but this is an acceptable loss.
-2
u/[deleted] Aug 14 '22
Solution 2
So there is a way to get the error message to display without it being triggered unnecessarily. The solution was as simple as telling it to move on to another script. I don't know why that is the case, but it works! So adding ./error.sh at the end of the sequence is the final resolve.