Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate bash/zsh expressions inline

Tags:

bash

zsh

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.

like image 333
nunos Avatar asked Sep 27 '26 08:09

nunos


1 Answers

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.

like image 158
hek2mgl Avatar answered Sep 30 '26 14:09

hek2mgl