Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I frequently find myself doing something like the following:

$ big long command 1
$ big long command 2
$ diff -u <(big long command 1) <(big long command 2)

How can I get the shell (bash in my case) to construct that third command for me, without the need to cut and paste those big long commands into the <()s? (It's obviously fine if the big long commands are re-executed; they are assumed to be safe to re-run.)

share|improve this question

1 Answer 1

up vote 7 down vote accepted

You can use the Bash shell's history to get those last 2 run commands like so:

$ big long command 1
$ big long command 2
$ diff -u <(!-2) <(!-1)

This will take the current command minus 2 (big long command 1) and the current command minus 1 (big long command 2) and run them into diff.

References

share|improve this answer
    
also, you can pipe the output to diff if you wanted (although in this case may not have sense if you want to view the complete output before diffing): $ big long command 1; $ big long command 2 | diff -u <(!-1) - –  Carlos Campderrós Jul 17 '13 at 22:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.