Shells
About
-
A command interpreter allowing interaction with the OS.
-
Processes typed commands and executes programs.
-
When you open a terminal, the shell is the program that receives your commands.
Windows: Shells without native support
-
Some shells are not natively supported, but can be used on Windows through:
-
WSL .
-
Msys2 .
-
GitBash .
-
CygWin .
-
-
This also applies to TMux .
No Shell
win32 API
Create Processes
-
CreateProcessW
File Association
-
Use
ShellExecuteExorShellExecuteW, to open files by association (e.g.,foo.pdfwith Acrobat). -
CreateProcessdoes not handle file associations.
UAC Elevation
-
CreateProcessWruns with the caller’s token. It will not trigger UAC elevation. -
To elevate use
ShellExecuteExwithrunasor useCreateProcessWithTokenW/CreateProcessAsUserwith the right token.
"Conveniences" you lose by not using a shell
-
Built-ins :
-
Will not run
dir,cd, or othercmd.exebuilt-ins. Those are implemented inside the shell.
-
-
.bat / .ps1 files :
-
*.bat,*.cmd,.ps1are not native executables. -
*.batmust be run by cmd.execmd.exe /c yourscript.bat(or use the shell). -
*.ps1must be run by PowerShell (or invoked viapwsh -File).
-
-
Pipes :
-
This refers to the usage of something like:
-
>-
cmd.exe: Redirect stdout to a file (overwrite).
-
powershell: Redirect stdout to a file (overwrite).
-
-
|-
cmd.exe: byte-stream pipe.
-
powershell: object pipeline.
-
-
-
You must create pipes yourself and wire
STARTUPINFO.hStdInput/hStdOutputandbInheritHandles. -
You control the environment block and current directory. If you want inherited handles or specific stdio redirection you must set those in
STARTUPINFOand usebInheritHandles. -
Odin does this with the
win32api by:
&win32.STARTUPINFOW{ cb = size_of(win32.STARTUPINFOW), hStdError  = stderr_handle, hStdOutput = stdout_handle, hStdInput  = stdin_handle, dwFlags = win32.STARTF_USESTDHANDLES, }, -
-
Conditionals :
-
This refers to the usage of something like:
-
||-
cmd.exe: run RHS if LHS fails.
-
powershell: run RHS if LHS fails.
-
-
&&-
cmd.exe: run RHS if LHS success.
-
powershell: run RHS if LHS success.
-
-
-
Parent or shell must implement conditional logic. Parent must check exit code and decide.
-
-
Sequence invoke :
-
This refers to the usage of something like:
-
&-
cmd.exe: Command operator. Runs next command unconditionally.
-
-
;-
powershell: Command operator.
-
-
-
If you want sequencing invoke multiple
CreateProcessWcalls or implement sequencing logic in your program.
-
Shells
Commands from tools
Help
-
tldr :
-
tldr
-
View Directory Contents
-
eza :
-
l -
l2 -
l3 -
lr -
ll
-
Search
-
fzf :
-
fd-
find dir
-
-
ff-
find file
-
-
Change Directory
-
zoxide
-
z
-
cmd.exe
-
OSs :
-
Windows.
-
Default on macOS since 2019.
-
-
Older Windows shell, present since Windows NT.
-
Limited compared to PowerShell, no support for advanced scripts.
Tokens
-
|-
Byte-stream pipe.
-
Stdout of left goes to stdin of right.
-
The shell creates an anonymous pipe and sets child std handles.
-
-
|>-
Not a thing.
-
-
>-
Redirect stdout to a file (overwrite).
-
-
2>-
Redirects stderr.
-
-
>>-
Appends.
-
-
||-
Run RHS only if LHS exit code != 0 (failure).
-
-
&&-
Run RHS only if LHS exit code == 0 (success).
-
-
;-
Not a thing.
-
Treated as a literal character unless quoted or part of a command argument.
-
-
&-
Command separator. Runs next command unconditionally.
-
Commands
-
help -
cls-
Clears the terminal
-
-
cd/chdir-
Change Directory
-
-
dir-
See contents of directory (
lsequivalent).
-
-
cat <file>/type <file>-
Sees the content of the file.
-
-
mkdir <dir>-
Create directory
-
-
del <file>-
Remove files.
-
-
copy NUL <file>-
Create empty file.
-
-
rmdir /s /q <dir>-
Remove directory.
-
I'm not sure about the flags.
-
-
move <from> <to>-
Move file.
-
-
copy <from> <to>-
Copy file.
-
-
rename <old> <new>-
Rename file.
-
-
find <text> <file>-
Find in file.
-
-
start <file>-
Opens IN Explorer.
-
-
explorer-
Opens THE Explorer.
-
-
systeminfo-
System information.
-
CPU-Z and GPU-Z are better.
-
Doesn't show much.
-
-
ipconfig
PowerShell
-
OSs :
-
Windows.
-
-
Replaces Command Prompt as Microsoft’s official tool.
-
Based on .NET, supports objects instead of just text.
-
Can run traditional Windows commands (
dir,ipconfig) and advanced scripts (.ps1).
Configuration
-
$PROFILE-
Shows the desired path for the configuration file.
-
Tokens
-
|-
Object pipeline. Cmdlets pass .NET objects (not raw bytes). When external programs are involved PowerShell passes text through std streams.
-
-
|>-
Forward-pipe operator in PowerShell 7+. It passes the left-hand value as the first argument to the right-hand command or script block.
-
Different from
|which is an object pipeline.
-
-
>-
Redirect stdout to a file (overwrite).
-
-
2>-
Redirects stderr.
-
-
>>-
Appends.
-
-
||-
Conditional OR in PowerShell 7+, running RHS if LHS failed.
-
-
&&-
Conditional AND in PowerShell 7+, running RHS if LHS sucess.
-
-
;-
Command separator.
-
Example:
Get-Process; Get-Serviceruns both commands sequentially.
-
-
&-
Call operator, used to invoke a command, script, or scriptblock stored in a variable or string.
-
Example:
& 'C:\script.ps1'.
-
Commands
-
help -
cls/clear-
Clears the terminal
-
-
ls/gci(Get-ChildItem) /dir-
See contents of directory.
-
-
cd/chdir/sl(Set-Location)-
Change Directory
-
-
mkdir/ni-
Create directory
-
If the file doesn't exist, it creates it.
-
Does not update the modification date of an existing file.
-
-
del-
Remove files or directories
-
-
cat-
Sees the content of the file.
-
-
start-
Opens IN Explorer.
-
-
explorer-
Opens THE Explorer.
-
-
systeminfo-
System information.
-
CPU-Z and GPU-Z are better.
-
Doesn't show much.
-
-
ipconfig
NuShell
-
NuShell .
-
It was recommended to me.
-
Crossplatform, Rust.
-
Starship
-
OSs :
-
Windows
-
Linux.
-
MacOS.
-
Default on macOS since 2019.
-
-
-
Features :
-
Written in Rust.
-
Supposedly better than Zsh.
-
-
Impressions :
-
Cross-platform is nice.
-
Nice customization.
-
Nice.
-
Cool.
-
Bash (Bourne Again Shell)
-
OSs :
-
~Windows (no native support)
-
Linux
-
Default in most Linux distributions.
-
-
MacOS.
-
-
Supports scripts, variables, loops, and customization via
~/.bashrc. -
To check if using Bash:
echo $SHELL-
If output is
/bin/bash, you are using Bash.
-
Commands
-
man-
[man]ual in Linux.
-
-
ls-
See contents of directory.
-
-
cat-
See contents of file.
-
-
cls/clear -
cd-
Change directory.
-
-
pwd-
Shows current directory.
-
-
touch-
If the file doesn't exist, it creates it.
-
If the file already exists, it updates the modification date without altering the content.
-
-
rm <file>-
Remove file.
-
-
mkdir <dir>-
Make directory.
-
-
rm -r <dir>-
Remove directory.
-
-
cp <from> <to>-
Copy file.
-
-
mv <old> <new>-
Rename file.
-
-
grep <text> <file>-
Find in file.
-
-
ps-
Show processes.
-
-
kill <PID>-
Kill a process.
-
Zsh (Z Shell)
-
OSs :
-
~Windows (no native support)
-
Linux.
-
MacOS.
-
Default on macOS since 2019.
-
-
-
More powerful than Bash.
-
Advanced autocompletion and command suggestions.
-
Better support for plugins and themes , with frameworks like Oh My Zsh .
-
Supports advanced globbing (
**/*.txtfinds all.txtfiles in subfolders). -
Install on Linux :
sudo apt install zsh # Debian/Ubuntu sudo pacman -S zsh # Arch Linux sudo dnf install zsh # Fedora-
Make default:
chsh -s $(which zsh)
-
Themes
Fish (Friendly Interactive Shell)
-
OSs :
-
~Windows (no native support).
-
Linux
-
macOS
-
-
Extremely easy to use and interactive.
-
Automatic command suggestions with history.
-
Syntax more intuitive than Bash/Zsh.
-
Incompatible with Bash scripts, may cause issues for advanced users.
-
To install:
sudo apt install fish # Debian/Ubuntu sudo pacman -S fish # Arch Linux sudo dnf install fish # Fedora -
To test:
fish
GitBash
-
Based on MinGW.
-
Comes with 'Git for Windows', allowing use of Unix commands (
ls,grep,vim).