MacBook, defective by design banner

title:
Put the knife down and take a green herb, dude.


descrip:

One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com

Using 89% of the same design the blog had in 2001.

FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white.

As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green.

x

MarkUpDown is the best Markdown editor for professionals on Windows 10.

It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support.

Features you won't find anywhere else include...

You've wasted more than $15 of your time looking for a great Markdown editor.

Stop looking. MarkUpDown is the app you're looking for.

Learn more or head over to the 'Store now!

Thursday, May 07, 2026

Note to self:

for /f "tokens=*" %i in ('git branch --format="%(refname:short)" ^| findstr /C:"feature/"') do @echo git branch -m "%i" "old/%i"

Then remove @echo to make it "really happen".

(That adds old/ to the front of anything that starts with feature/.)

Labels: , ,


posted by Jalindrine at 5/07/2026 11:38:00 AM
Wednesday, January 11, 2023

Remember when I said this?

but if I want something quick that can run anywhere [someone's on Windows], I use a batch file, and over the years, kinda like VIm, I've slowly become if not proficient then at least competent.

What a naรฏve time that was.


Take this seemingly innocuous question on SO:

How can you you insert a newline from your batch file output?

And then check this answer:

Here you go, create a .bat file with the following in it :

@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
echo There should be a newline%NL%inserted here.

echo.
pause

Wha? set NL=^^^%NLM%%NLM%^%NLM%%NLM%??? What in the world? Huh?

Luckily (?) one of the commenters asked the same question.

Here's part of the answer:

The caret is an escape character for the next character, or at the line end it is used as multiline character, but this is nearly the same.

At the line end it simply escapes the next character, in this case theย <Linefeed>, but there is a hidden feature, so if the escaped character is aย <LF>ย it is ignored and the next character is read and escaped, but this charater will be always escaped, even if it is also aย <LF>.

...

So you need to add an escaped linefeed into the line and that is the NL-Variable. The NL-Variable consists of only three characters.
NL=^<LF><LF>ย And if this is expanded, it creates only one escapedย <LF>ย as the firstย <LF>ย after the caret will be ignored.

I mean, um, that requires Inception level cognition to understand. ๐Ÿ˜ (Okay, actually it's pretty straightforward, but talk about a lack of discoverability.)

What's even more interesting is that dev's answer to the original question, which is this:

Like the answer of Ken, but with the use of the delayed expansion.

setlocal EnableDelayedExpansion
(set \n=^
%=Do not remove this line=%
)

echo Line1!\n!Line2
echo Works also with quotes "!\n!line2"

Aside

Okay, before I point out what I want to point out, note that %=_____=% is an inline comment format for batch.

From ss64.com, a common domain when I'm in batchland:

Batch variableย namesย can contain spaces and punctuation, we can take advantage of this fact by typing our comment as a non-existent variable. Because it doesnโ€™t exist, this variable will expand to nothing and so will have no effect when the script is run.

n.b. This only works in batch files, not directly at the command prompt.

To be sure that we donโ€™t accidently choose a name which is in fact a real variable, start and end the comment with "="

@Echo off
Echo This is an example of an %= Inline Comment =% in the middle of a line.

(Variable names starting with "=" are reserved for undocumented dynamicย variables. Those dynamic variables never end with "=", so by using an "=" at both the start and end of our comment, there isย noย possibility of a name clash.)


And we're back

Okay, now what I'd like to point out here is the setlocal EnableDelayedExpansion, something I think I had to use recently in a script I wrote. It's a bizarre new world.

Here's some explanation from ss64.com:

EnableDelayedExpansion

Delayed Expansion will cause variables within a batch file to be expanded at execution time rather than at parse time[;] this option is turned on with the SETLOCAL EnableDelayedExpansionย command.

Variable expansion means replacing a variable (e.g.ย %windir%)ย with its valueย C:\WINDOWS

  • By default expansion will happen just once, before each line is executed.
    In this case, a "line" includes bracketed expressions even if they are formatted to run over several lines.

  • Whenย !delayed!ย expansion is turned on, the variables will be expanded each time the line is executed, or for each loop in a FOR looping command.

And here's a decent example from that page showing how it works in practice.

@echo off
SETLOCALย EnableDelayedExpansion
Set "_var=first"
Set "_var=second"ย & Echo %_var% !_var!

The output is

first second

Note that the above example has to be in a batch file to work properly.

Anyhow, it's an insane rabbit hole that I didn't schedule for this sprint and fell into anyhow. I'm going to cut my losses now that I've warned others who may have been as naรฏve about batch scripts as I was, oh so long (less than three weeks ๐Ÿ˜‰) ago.


Oh good heavens. I guess this makes sense. The first example can be taken by itself as a brain teaser, I think.

From ss64.com, again on EnableDelayedExpansion:

@echo off
Setlocal
Set _html=Hello^>World
Echo %_html%

In the above, the Echo command will create a text file called 'world' - not quite what we wanted!

Got that figured out? If not, sit and think about it for a second before reading more.

Got it? Good. Clever, huh?

This is because the variable is expanded at parse time, so the last line is executing Echo Hello > World and the > character is interpreted as a redirection operator.

If we now try the same thing with EnableDelayedExpansion:

Setlocal EnableDelayedExpansion
Set _html=Hello^>World
Echo !_html!

With delayed expansion, the variable (including the > ) is only expanded at execution time so the > character is never interpreted as a redirection operator.

This makes it possible to work with HTML and XML formatted strings in a variable.

Labels: , , ,


posted by ruffin at 1/11/2023 12:27:00 PM
Thursday, December 22, 2022

The longer I work in Windows, the more I find myself using cmd.exe. I use PowerShell plenty too, but if I want something quick that can run anywhere [someone's on Windows], I use a batch file, and over the years, kinda like VIm, I've slowly become if not proficient then at least competent.

Nearly (and maybe even over at this point) thirty years ago I had a guy wisely tell me, when I was considering buying a new Mac or Windows PC, "It's all zeros and ones." Same for script languages, mostly. It might be a pain to learn batch scripting on Windows sometimes, but there's very little you can't do if you set your mind to it.

But this is a really neat trick to create "arrays" in batch that I've never seen. I've edited a bit to allow running in a .bat cleanly:

REM https://stackoverflow.com/questions/18462169/how-to-loop-through-array-in-batch

echo off


set Arr[0]=apple
set Arr[1]=banana
set Arr[2]=cherry
set Arr[3]=donut

set "x=0"

:SymLoop
if defined Arr[%x%] (
    call echo %%Arr[%x%]%%
    set /a "x+=1"
    GOTO :SymLoop

Clever.


While I'm at it, here's a PowerShell script I've been using to approximate grep there. I've dabbled in this problem before, but it's usually a good idea to reduce it to script instead of leaving only human-readable lessons learned:

param (
    [Parameter(Position=0)]
    [string]$needle,
    [Parameter(Position=1)]
    [string]$filepathToSearch,
    [Parameter(Position=2)]
    [string]$optionalFileForOutput
)

if ($optionalFileForOutput) {
    Get-ChildItem -Path $filepathToSearch |Select-String -Pattern $needle |Out-File -width 99999 $optionalFileForOutput
} else {
    select-string -path $filepathToSearch -pattern $needle
}

That captures the Out-File wackiness from the previous post but also wraps Select-Stringing a file, making it easier to remember, not that it's difficult. I should fix the casing.

Labels: , , , ,


posted by ruffin at 12/22/2022 10:21:00 AM
Sunday, January 05, 2020

How had I never learned this?

If, for example, you knew that the file had bob somewhere in the file, you would type:
dir *bob*.* /s
That's borderline embarrassing. I've even used tree /a /f > out.txt and then searched that text file.

Major Facepalm.

Labels: , , ,


posted by ruffin at 1/05/2020 09:46:00 AM

<< Older | Newer >>


Support freedom
All posts can be accessed here:


Just the last year o' posts:

URLs I want to remember:
* Atari 2600 programming on your Mac
* joel on software (tip pt)
* Professional links: resume, github, paltry StackOverflow * Regular Expression Introduction (copy)
* The hex editor whose name I forget
* JSONLint to pretty-ify JSON
* Using CommonDialog in VB 6 * Free zip utils
* git repo mapped drive setup * Regex Tester
* Read the bits about the zone * Find column in sql server db by name
* Giant ASCII Textifier in Stick Figures (in Ivrit) * Quick intro to Javascript
* Don't [over-]sweat "micro-optimization" * Parsing str's in VB6
* .ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture); (src) * Break on a Lenovo T430: Fn+Alt+B
email if ya gotta, RSS if ya wanna RSS, (?_?), ยข, & ? if you're keypadless


Powered by Blogger etree.org Curmudgeon Gamer badge
The postings on this site are [usually] my own and do not necessarily reflect the views of any employer, past or present, or other entity.