10

I'm writing a shell script that needs to download some data from the Internet and I was just thinking if I can rely on cURL that it's pre-installed on all Unix distributions.
I know that wget is not on OS X by default but cURL is. I also remember me installing cURL on Ubuntu Server but it's already a year or two. I tried Ubuntu Server 12.04 today and it comes with cURL out of the box.

martin
  • 355
  • 1
  • 7
  • 15

7 Answers7

12

No, cURL is not a standard part of operating systems. It isn't ever standard on all Linux based distributions.

Daniel Pittman
  • 5,842
  • 1
  • 23
  • 20
  • 8
    Is there some kind of list available for each distribution with all pre-installed commands? – martin Jun 14 '12 at 07:24
  • 1
    As per https://daniel.haxx.se/docs/curl-vs-wget.html, "**curl** comes pre-installed on **macOS** and **Windows 10**. **Wget** does not." – computingfreak May 17 '21 at 09:21
7

Neither curl nor wget are "guaranteed" to be installed anywhere, especially on proper UNIX systems. They are not POSIX standards. Neither is ftp, ssh / scp / sftp, rsync, telnet, nc / netcat, openssl, or probably any related tool that comes to mind. It seems like an odd oversight to me, but that is how it is.

Various GNU/Linux distros may include curl and/or wget, but YMMV.

FreeBSD comes standard with the "fetch" tool for cases like this and OpenBSD comes with a souped-up "ftp" client that can do the job with it's "AUTO-FETCHING" feature.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/

To my knowledge, there is no "tcp" file transfer tool defined by POSIX at all. uucp is standard, but I do not know if you could even make that work without config changes on both ends.

You can test for both of them (as many have suggested), but to be certain you would either need to install something or write something.

A shell with tcp socket support (like ksh93 or Bash) should let you write a function call in a pinch. Of course, you still need the proper permissions to read / write to the socket.

GNU awk ("gawk") can do it, however the odds of having gawk and nothing more convenient like curl or wget seems slim to me. Pretty sure POSIX awk does not support networking and I do not recall seeing anything about it in "The AWK Programming Language" but it has been a while. Of course, Perl, Python, Ruby, C, etc. can do it also.

See: https://www.shell-tips.com/bash/download-files-from-shell/

https://unix.stackexchange.com/questions/83926/how-to-download-a-file-using-just-bash-and-nothing-else-no-curl-wget-perl-et

https://unix.stackexchange.com/questions/336876/simple-shell-script-to-send-socket-message

Note: As of 2022, Project Gutenberg no longer seems to support insecure downloads over Port 80, so the script example below has been updated with a HTTP mirror.

#!/bin/ksh

## Tested with ksh93u+ and Bash v3.2x
## Not tested with Binary files
## HTTP/1.1 will cause output to hang

#xHOST=gutenberg.org
#xDOC=/files/84/old/84.txt

gpHOST=mirrors.xmission.com
gpDOC=/gutenberg/8/84/old/84.txt
gpPORT=80

exec 3<>/dev/tcp/${gpHOST}/${gpPORT}
printf "GET ${gpDOC} HTTP/1.0\r\nHost: ${gpHOST}\r\n\r\n" >&3

# drop the header from the data stream
while IFS= read -r line ; do
   [ "$line" == $'\r' ] && break
done <&3

cat <&3 | tee Frankenstein.txt

Pro tip: "tar" is not POSIX either! Use "pax" instead.

Kajukenbo
  • 71
  • 1
  • 3
6

Everything else equals I would say it being more likely that you have wget installed.

Yet, why not simply make a conditional, looking for both wget and curl in the PATH, and use whatever is available, if any? If you want to be ambitious, also feel free to through in lynx, w3m, etc in the mix.

andol
  • 6,938
  • 29
  • 43
3

Since some machines tend to have curl and others tend to have wget pre-installed, I sometimes use this in Bash scripts :

# use curl or wget, depending on which one we find
curl_or_wget=$(if hash curl 2>/dev/null; then echo "curl -s"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi);

if [ -z "$curl_or_wget" ]; then
        echo "Neither curl nor wget found. Cannot use http method." >&2
        exit 1
fi

x=$($curl_or_wget "$url")
mivk
  • 4,004
  • 3
  • 37
  • 32
1

Thought I'd update here since the answers are almost 10 years old.

linuxize.com

The curl package is pre-installed on most Linux distributions today.

However when automating you probably don't want to expect it. I'm using this but improvements would be great :)

if glide --version; then
    echo "Glide is installed"
else
    echo "Installing Glide."
    if curl; then
        curl https://glide.sh/get | sh
    elif wget; then
        wget https://glide.sh/get | sh
    else
        echo "curl and wget are not available, install glide manually"
    fi
fi
Ben Racicot
  • 123
  • 5
0

It should be available for all major distributions, though not considered part of OS generally, and if it is not installed, any admin can install it. since it is opensource, even distros that don't have it can compile it. There is a windows port as well.

johnshen64
  • 5,865
  • 24
  • 17
0

It doesn't come with AIX. It's a pain in the butt to install on AIX, lots of dependencies.

awojo
  • 224
  • 3
  • 5