Visit Jeremy's Blog.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

["SOLVED"] Weird failure in bash string comparison

Posted 05-02-2016 at 01:43 AM by the dsc
Updated 05-02-2016 at 01:52 AM by the dsc

A string produced by a given command is somehow different from a string produced by "catting" a file produced by redirecting the output of the very same command. That's weird, if you ask me.

The "solution" is not to compare them both, but create a second file from the "same" redirection, and then strings from "catting" those files. Then the comparison won't always say the strings are different.

apps=$(ps -axo comm | grep "|firefox\|chromium\|kwrite\|kate\|kcalc\|curl\|wget\|lxterminal\|konsole\|konqueror\|dolphin\|systemsettings5\|mpv\|vlc" )

echo $apps > /dev/shm/appsnow

appsnow=$(cat /dev/shm/appsnow)

prevapps=$(cat /dev/shm/prevapps 2>/dev/null)

echo apps...... \"$apps\"
echo appsnow... \"$appsnow\"
echo prevapps.. \"$prevapps\"


if [[ "$apps" == "$prevapps" ]] ; then

echo same apps comparing vars from different commands


echo different apps comparing vars from different commands

echo $apps > /dev/shm/prevapps


if [[ "$appsnow" == "$prevapps" ]] ; then

echo same apps comparing vars coming from cat


echo different apps comparing vars coming from cat

echo $apps > /dev/shm/prevapps


exit 0
Posted in Uncategorized
Views 403 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 05:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration