Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
echo "Mary had a little lamb" > A
echo "Mary had not a little lamb" > B
echo Test 1
if cmp -s A A; then
echo > /dev/null
else
echo diff
fi
echo Test 2
if cmp -s A B; then
echo > /dev/null
else
echo diff
fi
Output :
Code:
Test 1
Test 2
diff
I need something that produce nothing (yet respect bash if-then-else) and the best I can think of is
echo > /dev/null
echo will not be good enough since it will produce an empty line that upsets other script.
and later you can do whatever you want based on that variable.
Do not attempt to echo anything and use (process) that later, that is just not reliable. Use exit code and variables.
Personally, i could not agree more with this comment.
Quote:
Also, personally, I prefer to write code that is more "human friendly". It's often possible to restructure code to be more concise or even efficient. But when that's not critical, I prefer my code to be more readable for whichever developer comes along afterwards. (I also like commenting my code.) – osullic Jan 6 at 10:08
just because I have not learned : and I am forced to negate my logic that is silly. I will rather learn things properly.
Thanks for all the tips from all posts!
As it was described on that link: : is not a noop, but a valid command which has a regular exit code too (which is always 0 - true). Actually it accepts command line arguments and for example
Code:
: $(ls /tmp > /tmp/aaa)
will execute that ls command (so it is definitely not a noop). true is a more human readable synonym of the same command. Additionally we also have a /bin/true binary executable. true has a counterpart, the command false, which works exactly the same way, the only difference is that it returns always a non-zero exit code (=false).
we used to construct for example an endless loop using it:
There isn't a missing semi-colon - a command can be terminated by a semi-colon or a newline (or an ampersand, which runs it in async in background).
In the examples above, the need for a colon after "then" is because the then must be followed by a command, for example, this is a syntax error: "if something; then; something; fi"
However, replacing all three semi-colons with newlines is valid - the "then" must be followed by a command, but can be separated from it by whitespace (i.e. the newline isn't a terminator in that context).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.