cancel
Showing results for 
Search instead for 
Did you mean: 

"diff" command with variables

SOLVED
Go to solution
dev44
Regular Advisor

"diff" command with variables

Is there a way to use the diff command with variables?

x=string 1 0
y=string 1 2
diff $x $y

the diff doesn't work.....
usage: diff [ -C n ] [ -S name ] [ -bcefhilnrstw ] dir1 dir2
diff [-C n ] [ -bcefhintw ] file1 file2
diff [ -D string ] [ -biw ] file1 file2
whatever
2 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: "diff" command with variables

Hi:

As the usage of 'diff' clearly shows, you need to specify two FILES. If you want to compare strings use the shell's 'test':

# X="string 1 0"
# Y="string 1 2"
# [ "${X}" = "${Y}" ] && echo "equal" || echo "not equal"
not equal

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: "diff" command with variables

dev, (?)

What is the really problem you are trying to solve?
What are you looking to get out of the difference command that a simple SHELL string compare can not offer?
- Specific output format?
- Your example does not show any switched, but were there options you intended to activate?

fwiw,
Hein.