Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I realize that the diff command is reserved for directories/files, but I've seen it being able to read from standard input, so that's not necessarily true.

Is it possible to somehow compare two variables that were stored in a ksh script?

The code looks like this:

a=$(cut -c 1-10 first_file.txt)
b=$(cut -f '3' -d ' ' second_file.txt)

#what I would like to do
$(diff $a $b) > differences.txt
share|improve this question
add comment

1 Answer

Use process substution (thanks, Dennis!) as described here. This would probably do it

diff <(echo $a) <(echo $b)

At least, that worked for me in bash on cygwin.

share|improve this answer
    
That's process substitution rather than input redirection. –  Dennis Williamson Jan 6 '11 at 21:14
    
Well, with the <, it's both, right? –  mfinni Jan 6 '11 at 21:16
    
Nope, I'm wrong, you're right. –  mfinni Jan 6 '11 at 21:17
    
Sorry, ksh doesn't like it. –  Nitrodist Jan 6 '11 at 21:32
    
So figure out the syntax for process substitution on ksh. –  mfinni Jan 6 '11 at 21:34
show 1 more comment

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.