Diff on two variables

diff <(echo "$a") <(echo "$b")
You got some results in two variables within your shell script and would like to find the differences? Changes in process lists, reworked file contents, ... . No need to write to temporary files. You can use all the diff parameters you'll need. Maybe anything like $ grep "^>" is helpful afterwards.

By: olorin
2009-07-15 07:26:23

These Might Interest You

  • This form is used in patches, svn, git etc. And I've created an alias for it: alias diff='diff -Naur --strip-trailing-cr' The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like svn diff --diff-cmd 'diff --strip-trailing-cr'... Show Sample Output

    diff -Naur --strip-trailing-cr
    ruslan · 2011-02-10 14:32:42 0
  • get subversion diff output without distracting whitespace changes. good for when you are cleaning up code to make sure you didn't change anything important. also useful when working with old code, or someone else's code.

    svn diff --diff-cmd diff -x -uw /path/to/file
    katylava · 2009-02-10 20:39:54 1
  • When running a long `diff -r` over folders, this simulates a "verbose" mode where you can see where diff is in the tree. Replace $file with the first part of the path being compared.

    lsof -c diff -o -r1 | grep $file
    d0g · 2014-01-29 18:35:28 1
  • Diff 2 branches, for a type of file & having a string in the diff

    git diff t1_clone tlocal4 --name-only | grep -i "swift" | xargs git diff t1_clone tlocal4 --word-diff-regex="NSLocalized"
    ashish2 · 2017-02-08 11:50:45 0

What Others Think

arcarbut · 465 weeks and 6 days ago
curious what the bourne (as opposed to bash) equivalent to this would be.
Korla_Plankton · 356 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: