1

How does one compare the filecontent difference between two remote files with a single line Shell command, without using Bash?

An attempt could be running a file attempt.sh with content:

#! /bin/sh
diff $(curl "https://raw.githubusercontent.com/dockerfile/ubuntu/master/README.md") $(curl "https://raw.githubusercontent.com/dockerfile/ubuntu/master/Dockerfile")

Note, as indicated here, the <() process substitution from bash is not available in shell.

xhienne
  • 5,738
  • 1
  • 15
  • 34
a.t.
  • 2,002
  • 3
  • 26
  • 66
  • Use [`rsync` in `--dry-run` (`-n`) mode`](https://unix.stackexchange.com/questions/57305/rsync-compare-directories). – Perette Feb 19 '21 at 18:59

1 Answers1

1

diff operates on files, not on content passed in parameter. Command substitution ($(...)) replaces the command with its content, this is not the tool you need.

What you actually need is what is called process substitution (<(...)), which replaces the command with a pseudo-file (actually a pipe) that contains (actually conveys) the result of the command, which is executed in a sub-process.

diff <(curl "https://raw.githubusercontent.com/dockerfile/ubuntu/master/README.md") \
     <(curl "https://raw.githubusercontent.com/dockerfile/ubuntu/master/Dockerfile")

Unfortunately, as you added in note, this is a bash extension that is not known to POSIX shells (/bin/sh). To my knowledge, there is no solution with /bin/sh and you have to save at least one of the two curl outputs in a file:

$ tmp=$(mktemp)
$ curl -o "$tmp" "https://raw.githubusercontent.com/dockerfile/ubuntu/master/README.md"
$ curl "https://raw.githubusercontent.com/dockerfile/ubuntu/master/Dockerfile" \
  | diff "$tmp" -
$ rm -f "$tmp"
xhienne
  • 5,738
  • 1
  • 15
  • 34