How to trim whitespace from a Bash variable?

A simple answer is: Xargs will do the trimming for you. It’s one command/program, no parameters, returns the trimmed string, easy as that! Note: this doesn’t remove all internal spaces so “foo bar” stays the same; it does NOT become “foobar”. However, multiple spaces will be condensed to single spaces, so “foo bar” will become “foo bar”. In addition it doesn’t remove … Read more

Error: “Cannot modify the return value” c#

This is because Point is a value type (struct). Because of this, when you access the Origin property you’re accessing a copy of the value held by the class, not the value itself as you would with a reference type (class), so if you set the X property on it then you’re setting the property on the copy and then discarding it, leaving … Read more

How to check if a variable is set in Bash?

(Usually) The right way where ${var+x} is a parameter expansion which evaluates to nothing if var is unset, and substitutes the string x otherwise. Quotes Digression Quotes can be omitted (so we can say ${var+x} instead of “${var+x}”) because this syntax & usage guarantees this will only expand to something that does not require quotes (since it either expands to x (which contains no word breaks so it … Read more

Append integer to beginning of list in Python

How it works: array.insert(index, value) Insert an item at a given position. The first argument is the index of the element before which to insert, so array.insert(0, x) inserts at the front of the list, and array.insert(len(array), x) is equivalent to array.append(x).Negative values are treated as being relative to the end of the array.

“No X11 DISPLAY variable” – what does it mean?

If you’re on the main display, then or if you’re using csh or tcsh before running your app. Actually, I’m surprised it isn’t set automatically. Are you trying to start this application from a non-graphic terminal? If not, have you modified the default .profile, .login, .bashrc or .cshrc? Note that setting the DISPLAY to :0.0 … Read more

“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

Notice: Undefined variable From the vast wisdom of the PHP Manual: Relying on the default value of an uninitialized variable is problematic in the case of including one file into another which uses the same variable name. It is also a major security risk with register_globals turned on. E_NOTICE level error is issued in case of working with uninitialized variables, however not … Read more