User Tools

Site Tools


kb:common:shell

Shell/Terminals

Windows Misc

Windows Environment Variables

Setting environment variables like PATH can be done via Control Panel → System:

Windows Command Interpreter

  C:\>cmd /?
  Starts a new instance of the Windows XP command interpreter
Usually you don't need to run it in a Command Prompt if it's an external command (executable, script, etc.). So if you can go to Start → Run… and run it from there, then you can run your application directly with all arguments, etc.

However, if you're using CMD builtin features, like internal commands (dir, echo, mklink, …), the pipe (|), or I/O redirection (>, », <), you must run the commandline in CMD, because otherwise these features wouldn't be available. The parameter /c is just to tell CMD to terminate after the command completes. It's not required, but it's good practice to put it there, so you can easily replace it with /k (keep CMD open after the command completes) for debugging purposes.

(Source: https://stackoverflow.com/questions/35802779/do-i-need-cmd-c)


Windows Batch

The Windows batch shell, commonly referred to as cmd, cmd.exe or the command prompt

Batch specific details:

  • variables are enclosed by % signs (e.g. %CI_DIR%)
  • NUL is the batch equivalent to the UNIX /dev/null
  • the rem keyword is a way to comment out code

Print variables via echo %VARIABLE%.


Windows Powershell

PowerShell

PowerShell is Microsoft's modern, cross-platform command-line shell and scripting language. Unlike cmd.exe, PowerShell passes structured objects through pipelines instead of plain text.

Windows includes Windows PowerShell 5.1 (powershell.exe). The newer PowerShell 7 (pwsh.exe) is installed separately and is recommended for new scripts:

winget install --id Microsoft.PowerShell --source winget
Commands and aliases

PowerShell commands typically follow the Verb-Noun convention:

Get-ChildItem
Get-Process
Set-Location

Some familiar commands such as ls, cd and pwd are PowerShell aliases. For example, ls invokes Get-ChildItem; it is not the Unix program.

List available commands or get help:

Get-Command
Get-Help Get-ChildItem -Online
Variables and environment variables

PowerShell variables use a $ prefix:

$name = 'Example'
Write-Output $name

Environment variables are accessed through the Env: provider:

$env:USERPROFILE
$env:LOCALAPPDATA
$env:PATH

Changes made this way apply only to the current process and its child processes:

$env:EXAMPLE = 'value'

See Microsoft: Environment variables for persistent user-level and system-level variables.

Quoting and executing commands

Use single quotes for literal strings and double quotes when variables should be expanded:

'$env:USERPROFILE'
"$env:USERPROFILE\Documents"

An executable found through PATH can be called directly:

git --version

Use the call operator & to execute a quoted path or a path stored in a variable:

& 'C:\Program Files\Example\tool.exe' --version
 
$tool = 'C:\Program Files\Example\tool.exe'
& $tool --version

The & is necessary because a quoted path by itself is treated as a string.

Calling cmd.exe

External executables can normally be called directly from PowerShell. Use cmd /c only for batch files, cmd.exe built-in commands, or command lines relying on cmd.exe syntax:

cmd /c 'example.cmd'
cmd /c 'echo Example > output.txt'
Files and hidden directories

Search recursively for a file:

Get-ChildItem $env:USERPROFILE -Filter example.dll -Recurse -ErrorAction SilentlyContinue

Use -Force to include and traverse hidden directories such as AppData:

Get-ChildItem $env:USERPROFILE -Filter example.dll -Recurse -Force -ErrorAction SilentlyContinue

Return only the complete paths:

Get-ChildItem $env:USERPROFILE -Filter example.dll -Recurse -Force -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty FullName
Splitting long commands

A command can usually be continued after a pipe, comma, opening bracket or other syntactically incomplete expression:

Get-ChildItem $env:USERPROFILE -Recurse -Force |
    Where-Object Extension -eq '.dll' |
    Select-Object -ExpandProperty FullName

For other cases, use the backtick as the final character on the line:

& 'C:\Program Files\Example\tool.exe' `
    --option 'value'

Avoid trailing spaces after the backtick.


Windows Terminal

“The Windows Terminal is a modern, fast, efficient, powerful, and productive terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and WSL. Its main features include multiple tabs, panes, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and custom themes, styles, and configurations.”

From the Microsoft Store

Installation

The Windows Terminal is not part of a default Windows 10 installation (but in Windows 11). The easiest way to install it, is with the Microsoft Store. Search for “Terminal” and the first hit should it be.

Configuration/Settings

The Windows Terminal can be configured very extensively, and it would go way too far to explain every option. I want to introduce only a few important settings.

Open the settings tab by clicking on the down arrow next to the “new-tab-plus” symbol.

  • Defautl profile when opening a new tab: In section “Start” direct the first setting on the top. You can select a profile on the dropdown menu.

Custom Profiles

All configured profiles can be modified under their profile section.

The button “Add new profile” allows adding own profiles. Click on the button “New empty profile” to create a complete new one.

You can add the Git Bash with the following settings.

kb/common/shell.txt · Last modified: 2026/07/23 07:26 by joerg.hampel