ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I am looking for a solution for comparing two variables without using a tmp file (written on hdd), and only work with variables. Target: I simply would like to output the new lines that have been seen into $Var2.
sthg like this for instance.
Code:
diff -someoptions $Var1 $Var2
Until now, I use this method (that I do not favor), because ram can do it as well
#!/bin/bash
Var1=$( /bin/cat << EOF
Some text
more text
Even more text
EOF
)
Var2=$( /bin/cat << EOF
Some text
more text
New text here
Even more text
And even more new text
EOF
)
/usr/bin/mkfifo fifo1 fifo2
echo "${Var1}" > fifo1 &
echo "${Var2}" > fifo2 &
/usr/bin/diff fifo1 fifo2
/bin/rm fifo1 fifo2
From man 7 fifo:
Code:
A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the
file system. It can be opened by multiple processes for reading or writing. When processes are
exchanging data via the FIFO, the kernel passes all data internally without writing it to the file
system. Thus, the FIFO special file has no contents on the file system; the file system entry
merely serves as a reference point so that processes can access the pipe using a name in the
file system.
EDIT:
I initially thought of the if-statement approach too fukawi1, but it sounds like the OP wants to see the new lines of Var2--not to just visually compare their values.
Last edited by Dark_Helmet; 01-12-2012 at 01:43 AM.
It's hard to say without some more context, but since you mention "adding new lines", it sounds like you might possibly want to consider using arrays instead.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.