nunos
nunos

Reputation: 21389

Evaluate bash/zsh expressions inline

I am aware that it's possible to do stuff like

echo `ls` "foobar"
echo $(ls) "foobar"

but when I try to do something like

diff `pip freeze` requirements.txt
diff $(pip freeze) requirements.txt

it fails.

What am I missing here? Thanks!

P.S I am using zsh shell.

Upvotes: 3

Views: 2380

Answers (2)

Accidental brine
Accidental brine

Reputation: 35

Try

diff =(pip freeze) requirements.txt

Upvotes: 0

hek2mgl
hek2mgl

Reputation: 157967

The diff command does expect file names as it's arguments, not strings. Something like:

diff file1 file2

but not:

diff "$string1" "$string2"

If you want to diff the output of two commands (or in your case the output of a command against a static file) you can use process substitution:

diff <(pip freeze) requirements.txt

The <() will redirect the output of pip freeze into a file at /dev/fd[0-9]. This file name will then getting passed to diff.

Upvotes: 8

Related Questions