Python equivalent to perl -pe?

Yes, you can use Python from the command line. python -c <stuff> will run <stuff> as Python code. Example: python -c “import sys; print sys.path” There isn’t a direct equivalent to the -p option for Perl (the automatic input/output line-by-line processing), but that’s mostly because Python doesn’t use the same concept of $_ and whatnot … Read more

WSL run linux from windows without spawning a cmd-window

Here’s a simpler solution, which, however, requires a WSH-based helper script, runHidden.vbs (see bottom section): wscript .\runHidden.vbs bash -c “DISPLAY=:0 xmessage ‘hello, world'” To apply @davv’s own launch-in-background technique to avoid creating a new bash instance every time: One-time action (e.g., at boot time): launch a hidden, stay-open bash window. This spawns 2 bash processes: … Read more

Run a script only at shutdown (not log off or restart) on Mac OS X

Few days ago I published on github a configuration/script able to be executed at boot/shutdown. Basically on Mac OS X you could/should use a System wide and per-user daemon/agent configuration file (plist) in conjunction with a bash script file. This is a sample of the plist file you could use: <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE plist … Read more

Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

How to get bc to handle numbers in scientific (aka exponential) notation?

Unfortunately, bc doesn’t support scientific notation. However, it can be translated into a format that bc can handle, using extended regex as per POSIX in sed: sed -E ‘s/([+-]?[0-9.]+)[eE]\+?(-?)([0-9]+)/(\1*10^\2\3)/g’ <<<“$value” you can replace the “e” (or “e+”, if the exponent is positive) with “*10^”, which bc will promptly understand. This works even if the exponent … Read more