Using Powershell environmental variables as strings when outputting files

js2010’s answer shows the effective solution: use “…”-quoting, i.e. an expandable string explicitly. It is a good habit to form to use “…” explicitly around command arguments that are strings containing variable references (e.g. “$HOME/projects”) or subexpressions (e.g., “./folder/$(Get-Date -Format yyyy-MM)”) While such compound string arguments generally do not require double-quoting[1] – because they are … Read more

How do I make Perl scripts recognize command-line parameters in the Win32 cmd console?

I found out what the problem was. Although the ftype and the assoc values were set as suggested, the actual behavior on my system seems to be determined by the registry key HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command It should have a (Default) string value of “C:\Perl\bin\perl.exe” “%1” %* When I found this entry, it was set to “C:\Perl\bin\perl.exe” “%1”. … Read more

Visual Basic scripting dynamic array

You can’t re-dimension a fixed-size array (Dim vprglist(10)). If you want a dynamic array, define a “normal” variable and assign an empty array to it: Dim vprglist : vprglist = Array() or define it directly with ReDim: ReDim vprglist(-1) Then you can re-dimension the array like this: If vprogram.LastRunTime = “” Then ReDim Preserve vprglist(UBound(vprglist)+1) … Read more

What is the difference between window.onload = init(); and window.onload = init;

window.onload = init(); assigns the onload event to whatever is returned from the init function when it’s executed. init will be executed immediately, (like, now, not when the window is done loading) and the result will be assigned to window.onload. It’s unlikely you’d ever want this, but the following would be valid: function init() { … Read more

Extract version number from a string

Following Kent’s answers, this can work: grep -Po ‘(?<=divider-bin-)\d.\d.\d’ and even better: grep -Po ‘(?<=divider-bin-)[^;]+’ it greps from divider-bin- until it find the ; character. This way any NNN.NNN. … . NNN format will work (no matter how many blocks of NN). Test: $ echo “data-c(kuh-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(kuh)-win2” | grep -Po ‘(?<=divider-bin-)[^;]+’ 1.4.4 $ echo “data-c(kuh-small1);divider-bin-1.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(kuh)-win2” | … Read more

Creating a script for a Telnet session?

I’ve used various methods for scripting telnet sessions under Unix, but the simplest one is probably a sequence of echo and sleep commands, with their output piped into telnet. Piping the output into another command is also a possibility. Silly example (echo password; echo “show ip route”; sleep 1; echo “quit” ) | telnet myrouter … Read more

Remove part of path on Unix

If you wanted to remove a certain NUMBER of path components, you should use cut with -d”https://stackoverflow.com/”. For example, if path=/home/dude/some/deepish/dir: To remove the first two components: # (Add 2 to the number of components to remove to get the value to pass to -f) echo $path | cut -d”https://stackoverflow.com/” -f4- # output: # some/deepish/dir … Read more