Chapter 22
In This Chapter
cmd.exe part ways — and why each matterscmd.exe workaround, where there is one)This is the bragging-rights chapter. Every shell ever written has things it does better and things it does worse than the competition; this chapter is about cshw vs. the default shell Windows ships with. It's not a fair fight (the cmd.exe lineage dates to 1981 and was never substantially updated past the basics), but the comparison is worth making — partly because new users genuinely don't know what they're missing, partly because the existence of this gap is the whole reason cshw exists in the first place.
A note before we start: this isn't an indictment of cmd.exe. cmd.exe is fine for the cases it was designed for — running a few commands in sequence, invoking an external program with a fixed argument list, basic batch-file automation. Its design lineage traces back to COMMAND.COM, which shipped with MS-DOS 1.0 on the original IBM PC in 1981. cmd.exe specifically arrived a decade later with Windows NT, but it inherited most of COMMAND.COM's command syntax and semantics — and forty-five years on, batch files written in 1985 still substantially work. That's not nothing.
cshw is what happens when someone asks "what if a Windows shell were as comfortable as a modern Unix shell, and also took advantage of being on Windows?" Different goals, different result. With that out of the way:
In cmd.exe, glob expansion is the calling program's problem. When you type del *.tmp, the wildcard is passed verbatim to del, which decides how to interpret it. Some commands handle wildcards; others don't; the rules vary command by command. There is no shell-level glob expansion.
In cshw, every built-in that touches files does its own glob expansion using the same matcher, so globs work consistently across commands:
del *.tmp # cshw expands *.tmp to the list of matching files
rm *.bak /s # use the command's recursion flag for subtree work
ls *.cpp *.h # multiple patterns combined
echo *.txt # echo gets the expanded list; you can see what matched
echo *.txt works as a test: type it before running anything destructive to confirm what the pattern actually matches.
TECHNICAL STUFF
Some cmd.exe commands like dir and del do handle wildcards internally — that's why they sort of work for simple cases. But the moment you want a wildcard for a command that doesn't handle them itself (your own program, a third-party tool, for loops), you have to write a for /f incantation. cshw uses the Win32 FindFirstFile semantics for the glob itself (*, ?, character classes), so there is no bash-style recursive ** — use a command's /s flag (or a foreach loop) for recursion. Brace alternation is supported, and it happens before globbing:
echo {a,b,c} # a b c
echo file{1,2,3}.txt # file1.txt file2.txt file3.txt
echo {a,{b,c}} # a b c -- nesting works
What is not supported is the bash {1..5} range form; {1..5} stays the literal text 1..5. Write the values out, or use a for loop when you want a counted sequence.
cmd.exe's control flow is famously hostile. Loops use a for /f syntax that's so famously incomprehensible there are stack overflow questions purely about parsing it. The if statement supports a handful of operators but no else if. Block syntax requires parentheses and is fragile around special characters.
cshw uses syntax that won't surprise anyone who's used a programming language:
if ($count > 10) then
echo "Lots."
else if ($count > 0) then
echo "Some."
else
echo "None."
endif
foreach file (`ls *.log`)
echo "Processing $file"
grep "ERROR" $file
end
while ($attempts < 3) then
fetch https://service.example.com/health
if ($? == 0) then
break
endif
@ attempts = $attempts + 1
sleep 1
end
loop 5 as i
echo "Iteration $i"
endloop
Read once, understand. Compare to the equivalent for /F "tokens=*" %%i in ('dir /b *.log') do ... and the gap is immediate.
In cmd.exe, the closest thing to a function is CALL :LABEL, which jumps to a label, runs until GOTO :EOF or a matching marker, then returns. Arguments are positional (%1, %2...), there's no return value mechanism beyond EXIT /B N for a numeric code, and local variables require explicit SETLOCAL/ENDLOCAL discipline.
In cshw, procedures are a first-class concept:
proc greet
echo "Hello, $1!"
@ greeting_count = $greeting_count + 1
return 0
endproc
greet "World"
greet "cshw"
echo "Said hello $greeting_count times"
Named procedures, named parameters via $1/$2/$argv, local-by-default variables, a return value via $result, recursion if you want it. Compose them, library them up with library, share them across scripts via source. The Chapter 10 toolkit.
cmd.exe has one data type: the string. You can simulate arrays with naming conventions (set arr_0=..., set arr_1=...) and write fragile loops to walk them, but it's painful and never feels right.
cshw has real arrays and hashes (Chapters 5 and 11):
declare -a colors
array push colors "red"
array push colors "green"
array push colors "blue"
foreach c ($colors)
echo "Color: $c"
end
declare -A config
hash set config name "MyApp"
hash set config version "1.2.0"
echo "App: $config[name] v$config[version]"
Indexed access, hash lookups, push/get/set, iteration, filtering and mapping with the patterns from Chapter 11. The shell starts to look like the small-scale programming language it actually is.
cmd.exe has command history within a session. Close the window, open a new one — it's gone.
cshw persists history across sessions automatically. Type something today; up-arrow finds it next week. The history file (~/.cshw_history or its equivalent) collects everything you've typed, indexed and searchable:
history # the full list
history 50 # most recent 50
Up-arrow walks back through entries interactively, the same as in any modern shell. Bang-history works too — !! re-runs the last command, !42 re-runs entry 42 from the history list, !grep re-runs the most recent command starting with "grep", and the word designators !$ (last argument of the previous command), !^ (first argument), and !* (all arguments) are wired up for picking pieces out of the previous line.
This sounds small. It isn't. Persistent history changes the daily texture of using the shell — you stop remembering commands you've used before, because the shell remembers them for you. Eventually you start thinking of the prompt as having a small extended-memory tied to your fingers.
cmd.exe has no & for backgrounding, no jobs to list what you've launched, no fg/bg to bring things forward. You can start a process and lose track of it; that's the entire job-control story.
cshw has real job control (Chapter 13):
long_running_command & # launch in background -- prompt returns
jobs # show running and stopped jobs
fg %1 # bring job 1 to foreground
bg %1 # resume in background after Ctrl+Z
kill %1 # terminate job 1
stop %1 # suspend job 1
wait # wait for all background jobs (alias for cowait /all)
The same affordances Unix users have had since 1981. Launch a build in the background, keep working in the foreground, check on it when you're ready. Multitasking at the shell level, with no separate-window overhead.
This one's the gap that's least surmountable in cmd.exe. There is no cmd.exe equivalent to running shell code concurrently with other shell code in the same process. None. Not awkward, not painful — missing.
cshw has coroutines (Chapter 14):
proc fetch_health
fetch -q https://$1/health
share result_$1 = "$?"
endproc
corunproc fetch_health api.example.com
corunproc fetch_health db.example.com
corunproc fetch_health cache.example.com
cowait /all
echo "API: $result_api.example.com"
echo "DB: $result_db.example.com"
echo "Cache: $result_cache.example.com"
Three health checks running in parallel, results gathered, total time = the slowest one. To do this in cmd.exe you'd have to spawn three separate cmd.exe processes via start, somehow coordinate the results back through files or signals, and accept that you've left the language entirely.
cmd.exe has zero built-in HTTP capability. To call an API from a .bat file, you shell out to curl.exe or powershell.exe and capture the output through environmental tricks.
cshw has fetch, ftpfetch, tcpclient, tcpserver, and the full socket family (Chapter 16):
# HTTP API call
fetch -X POST -d "name=alice" https://api.example.com/users
# Quick port-listening test
tcpclient localhost 8080
if ($? == 0) then
echo "Service is up."
endif
# A 12-line HTTP server, in the shell
proc http_handler(sock)
socket recv $sock
socket send $sock "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nHello"
socket close $sock
endproc
tcpserver 8080 http_handler
Network programming, native to the shell, with no external dependencies. The HTTP server fits in 12 lines and works.
cmd.exe was designed in 1987. AI integration was not on the list of considerations.
cshw has genai (Chapter 17):
genai ask "How do I find files modified in the last hour on Windows?"
# Pipe data into the AI
type error.log | genai ask "Summarize the top 3 issues in this log"
# Generate code on demand
genai code -l python "function to parse a CSV with custom delimiter"
This is the feature that makes a point about what a modern shell should be. The AI provider isn't a foreign tool you shell out to; it's a command, with proper exit codes, proper output streaming, proper integration with pipes and redirection. Combined with coroutines and fetch, it's how you write things like "analyze 1000 logs in parallel" in 30 lines.
cmd.exe has no extension mechanism. You can write a .exe and call it from cmd.exe, but it runs as a child process — separate memory, separate state, separate everything. There's no way to add a command to cmd.exe; the command set is hardwired.
cshw lets you add commands by writing a plugin DLL (Chapter 18):
// Your plugin
static CShwPluginCommandDef s_commands[] = {
{ L"mycmd", L"My new command", NULL, NULL, DoMyCmd, HelpMyCmd, TRUE, NULL }
};
CSHW_EXPORT_REGISTER(s_libInfo)
CSHW_EXPORT_UNREGISTER(/* cleanup */)
Compile to a DLL, load with rcl mylib.dll, and mycmd is now a first-class shell command — same redirection, same help system, same shadowing, same integration as any built-in. Plus rundllproc and winapi (also Chapter 18) for calling any existing Win32 function on the system from the shell directly.
For the kinds of tools that benefit from native-code performance or need to wrap an existing C/C++ library, this is the difference between "I have to write a separate utility" and "I have a new shell command." It's also the feature that earns cshw the title of Windows shell rather than shell that runs on Windows.
Some of cmd.exe's limitations are historical accidents. It was written for a world where 640K was enough RAM and shells weren't supposed to be programming environments. Some are deliberate — Microsoft has kept the cmd lineage (from COMMAND.COM forward) largely unchanged for forty-plus years specifically because batch files written in 1995 still need to work in 2026. Stability over features is a real engineering choice, and the cmd shell is very stable.
The catch is that "stable" and "good" aren't synonyms. cmd.exe has stayed essentially the same shell while every other major shell environment moved forward.
cshw isn't trying to dethrone cmd.exe in isolation. The honest comparison is against the modern shell landscape. Quick lay of the land:
Where cshw fits. Not as "another bash port" — Git Bash and WSL already cover that need. Not as "Nushell for csh nostalgics" — different philosophy. cshw is a different combination: csh-family interactive syntax + native Windows + built-in AI + plugin DLLs in C/C++ + coroutines in the shell. That mix doesn't exist elsewhere. You get a familiar text-stream shell with concurrency, a programmable native-code plugin model, direct Win32 access, and genai as a first-class command — all in a single ~10MB binary with no runtime.
It's not the right shell for everyone. If you want fish-style autocomplete polish, install fish. If you want Nushell's structured data model, run Nu. If you live in .NET, PowerShell is built for you. cshw is for the person who wants a small, fast, native Windows shell that doesn't make them feel like they've left Windows behind — and does let them reach into the platform the way only a native shell can.
That's the position. Familiar commands, familiar syntax, real concurrency, real networking, real AI integration, real Windows-platform leverage. Not because cmd.exe is bad — because cmd.exe never tried to be this, and the other modern shells either aren't native Windows or aren't csh-style.
cshw doesn't try to replace cmd.exe or PowerShell — it cooperates with them. Type mybackup.bat or deploy.ps1 at the cshw prompt and it runs: cshw hands the file to its canonical interpreter (cmd.exe /c for .bat/.cmd, pwsh.exe -File or powershell.exe -File for .ps1), pipes the output back through cshw's stdio, and surfaces the exit code on $status. Same trust model as launching any .exe.
That's the right way to handle these formats. cmd.exe IS the canonical batch interpreter, the same way bash is for .sh; reimplementing it inside cshw would be years of "be bug-compatible with forty years of cmd.exe quirks" for no real user benefit. PowerShell scripts likewise live in their own runtime. cshw's job is to make sure they run when you type them.
So your ~/scripts/ folder of accumulated .bat automation isn't abandoned. Move to cshw for new work; let your existing batch and PowerShell scripts keep doing their job exactly as before.
That's the comparison. We don't have to pick fights with cmd.exe to know cshw is a step forward; just listing the differences makes the case.
Chapter 23 covers the other side — Ten Tricks for When You're Stuck. Debugging scripts, recovering from mistakes, asking for help from the shell itself. The "you've got a problem, here's how to make progress" toolkit, distilled down to a list of ten patterns worth memorizing.
After that, the Appendix Cheat Sheet — the one-page reference you'll keep open in a tab.