Every command on this site is written for one of three shells: bash (Linux), zsh or bash (macOS) and PowerShell (Windows). On Windows a few commands are better in Git Bash, and those blocks are labelled bash. This page says which shell to open, and how the common things differ between them.
#Pick your shell
#Linux
Use bash, the default on Ubuntu, Debian, RHEL, Rocky and Amazon Linux. zsh works for every command here too.
Check:
echo "$SHELL"; bash --version | head -n 1You should see something like /bin/bash and GNU bash, version 5.2....
#macOS
Use Terminal or iTerm2 with the default zsh (since macOS 10.15). Every bash block on this site runs unchanged in zsh, with one exception noted where it matters: a # in an unquoted argument is a comment in bash but not in zsh, which only matters if you paste comments on the same line as a command.
Check:
echo "$SHELL"; zsh --versionYou should see /bin/zsh and zsh 5.9 ... or similar.
#Windows
Use PowerShell by default. Either Windows PowerShell 5.1 (built in, "Windows PowerShell" in the Start menu) or PowerShell 7 (pwsh, install with winget install -e --id Microsoft.PowerShell). Every PowerShell command here works in both unless it says otherwise. Windows Terminal (built into Windows 11) is the most comfortable window to run them in.
Use Git Bash (installed with Git for Windows) when a block is labelled bash on the Windows tab. That is the case for:
- the repository's own shell scripts, such as
deploy/kind/up.sh(Windows has noshof its own); openssl(Git for Windows ships it; PowerShell does not);- reading values out of
.env.localwithsed; - running the CMS, website and worker dev servers on the host (see Windows notes).
Do not use the old Command Prompt (cmd.exe): no command on this site is written for it.
Check, in PowerShell:
$PSVersionTable.PSVersion; $ExecutionContext.SessionState.LanguageModeYou should see a version (5.1... or 7.x) and FullLanguage. If the second line says ConstrainedLanguage, your organisation has locked PowerShell down: commands that call .NET directly (for example generating random bytes with [System.Security.Cryptography...]) will fail, and unsigned .ps1 scripts may not run. Every command on this site avoids those, and where one would need it the page gives a Git Bash way instead.
#WSL (Windows Subsystem for Linux)
WSL gives you a real Ubuntu on Windows, where the Linux tab's commands work as written. It is a good choice if you are comfortable with Linux, with three cautions:
- Tools installed in Windows (Docker Desktop, Chrome) and tools installed inside WSL are separate. Docker Desktop's "WSL integration" makes
dockerwork inside your WSL distribution; turn it on in Docker Desktop, Settings, Resources, WSL integration. - Keep the code inside the WSL filesystem (
~/kims, not/mnt/c/...). Working on/mnt/cis many times slower fornpm installand the site build. - Your AWS, kube and git configuration in WSL (
~/.aws,~/.kube,~/.gitconfig) is separate from Windows's (%USERPROFILE%\.awsand so on).
The engineer's own laptop used PowerShell and Git Bash, not WSL, so the Windows tab is what was actually tested on Windows.
#Equivalents
The same thing in each shell. Use this table when adapting a command or reading a log.
#Setting a variable for the next commands
export AWS_REGION=ap-south-2
echo "$AWS_REGION"export AWS_REGION=ap-south-2
echo "$AWS_REGION"$env:AWS_REGION = "ap-south-2"
$env:AWS_REGIONThe variable lasts until the window is closed. In PowerShell, $Region = "ap-south-2" (no env:) makes a PowerShell variable that programs do not see; use $env:NAME for anything a program like aws or node reads.
#Setting a variable for one command only
KIMS_LIGHTHOUSE=skip npm run site:build -- --from-dir apps/website/content-fixturesKIMS_LIGHTHOUSE=skip npm run site:build -- --from-dir apps/website/content-fixtures$env:KIMS_LIGHTHOUSE = "skip"; npm run site:build -- --from-dir apps/website/content-fixtures; Remove-Item Env:KIMS_LIGHTHOUSEPowerShell has no NAME=value command form. Set it, run, then remove it.
#Making a variable permanent
echo 'export AWS_PROFILE=kims' >> ~/.bashrcecho 'export AWS_PROFILE=kims' >> ~/.zshrc[Environment]::SetEnvironmentVariable("AWS_PROFILE", "kims", "User")Open a new window afterwards. If PowerShell is in Constrained Language Mode the Windows line fails; use Settings, System, About, Advanced system settings, Environment Variables, New (under "User variables") instead.
#Splitting a long command over several lines
| Shell | Continuation character | Example |
|---|---|---|
| bash, zsh, Git Bash | \ at the very end of the line |
kubectl -n kims \ |
| PowerShell | ` (backtick) at the very end of the line |
kubectl -n kims ` |
Nothing, not even a space, may follow the continuation character. The commands on this site are mostly on one line to avoid this; if you copy a multi-line bash command into PowerShell, either join it into one line or replace each trailing \ with a backtick.
#Quoting a JSON argument
JSON on the command line is where shells differ most. Prefer a file: almost every AWS CLI option that takes JSON also accepts file://name.json, and it works the same in every shell.
aws s3api put-bucket-cors --bucket <ASSETS_BUCKET> --cors-configuration file://cors.jsonIf you must pass JSON inline:
aws ssm start-session --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"host":["<RDS_ENDPOINT>"],"portNumber":["5432"],"localPortNumber":["15432"]}'aws ssm start-session --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"host":["<RDS_ENDPOINT>"],"portNumber":["5432"],"localPortNumber":["15432"]}'aws ssm start-session --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "host=<RDS_ENDPOINT>,portNumber=5432,localPortNumber=15432"On Windows the AWS CLI's shorthand syntax (key=value,key=value) avoids JSON quoting altogether. PowerShell 5.1 strips the double quotes inside a single-quoted JSON string before the program sees them, so '{"a":"b"}' arrives as {a:b} and fails to parse; PowerShell 7.3 and later pass it correctly. If you are unsure, use a file.
#Writing a file with exact content
When a page shows file content (a JSON policy, a YAML pod), save it with your editor (Other tools). If you create it from the shell, make sure of the encoding on Windows:
cat > cors.json <<'EOF'
[{"AllowedOrigins":["https://<CMS_HOST>"],"AllowedMethods":["PUT"],"AllowedHeaders":["content-type"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]
EOFcat > cors.json <<'EOF'
[{"AllowedOrigins":["https://<CMS_HOST>"],"AllowedMethods":["PUT"],"AllowedHeaders":["content-type"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]
EOFSet-Content -Path cors.json -Encoding ascii -Value '[{"AllowedOrigins":["https://<CMS_HOST>"],"AllowedMethods":["PUT"],"AllowedHeaders":["content-type"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]'In Windows PowerShell 5.1, > and Out-File write UTF-16 with a byte-order mark. The AWS CLI, kubectl and Node cannot read such a file as JSON or YAML. Always use Set-Content -Encoding ascii (or utf8 in PowerShell 7), or save from an editor as "UTF-8".
#Base64
printf '%s' 'hello' | base64 # encode: aGVsbG8=
printf '%s' 'aGVsbG8=' | base64 -d # decode: helloprintf '%s' 'hello' | base64 # encode: aGVsbG8=
printf '%s' 'aGVsbG8=' | base64 -D # decode (older macOS); -d also works on macOS 13 and later[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("hello")) # encode: aGVsbG8=
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("aGVsbG8=")) # decode: helloThe Windows lines call .NET and fail in Constrained Language Mode; Git Bash has base64 and works the same as Linux. Linux's base64 wraps output at 76 characters; add -w 0 for one line.
Reading a value out of a Kubernetes Secret (they are stored base64-encoded):
kubectl -n kims get secret kims-database -o jsonpath='{.data.url}' | base64 -dkubectl -n kims get secret kims-database -o jsonpath='{.data.url}' | base64 -d# Git Bash
kubectl -n kims get secret kims-database -o jsonpath='{.data.url}' | base64 -dThat prints a secret to your screen: do it only when you must, and clear the screen afterwards.
#Random secrets
openssl rand -base64 32openssl rand -base64 32# Git Bash (Git for Windows includes openssl)
openssl rand -base64 32You should see 44 characters ending in =. Kubernetes Secrets uses this directly inside the kubectl create secret command so the value never appears on screen.
#Typing a secret without it going into your history
Commands you type are saved in your shell history (~/.bash_history, ~/.zsh_history, PowerShell's ConsoleHost_history.txt). Never type a password or token as part of a command. Read it into a variable instead:
read -rs DB_PASSWORD && export DB_PASSWORDread -rs DB_PASSWORD && export DB_PASSWORD$s = Read-Host -AsSecureString "Password"; $env:DB_PASSWORD = [Runtime.InteropServices.Marshal]::PtrToStringBSTR([Runtime.InteropServices.Marshal]::SecureStringToBSTR($s)); Remove-Variable sThe terminal waits with nothing shown: paste or type the value and press Enter. Afterwards, refer to $DB_PASSWORD (bash) or $env:DB_PASSWORD (PowerShell). Remove it when done with unset DB_PASSWORD or Remove-Item Env:DB_PASSWORD. In Constrained Language Mode the Windows line fails; use Git Bash's read -rs instead.
In bash and zsh, a command that starts with a space is also left out of history if HISTCONTROL=ignorespace (bash) or setopt HIST_IGNORE_SPACE (zsh) is set. Do not rely on it unless you have checked.
#Did the last command work?
echo $?echo $?$LASTEXITCODE0 means success. In PowerShell, $? is only True or False and is less reliable for programs; use $LASTEXITCODE.
PowerShell shows stderr in red. git, kubectl, npm, helm and the migration runner print progress on stderr. PowerShell 5.1 colours it red and can wrap it in NativeCommandError even when the command succeeded. Judge by the last line of output and $LASTEXITCODE, never by the colour.
#curl
| Shell | Use | Why |
|---|---|---|
| bash, zsh, Git Bash | curl |
The real curl |
| Windows PowerShell 5.1 | curl.exe |
curl is an alias for Invoke-WebRequest, which takes different options and prints an object |
| PowerShell 7 | curl.exe (or curl) |
The alias was removed, but curl.exe always works |
Windows 10 1803 and later ship curl.exe in C:\Windows\System32. The null device is /dev/null in bash and NUL in PowerShell:
curl -s -o /dev/null -w "%{http_code}\n" https://translation.googleapis.comcurl -s -o /dev/null -w "%{http_code}\n" https://translation.googleapis.comcurl.exe -s -o NUL -w "%{http_code}\n" https://translation.googleapis.comAny status code (even 404) means the network path is open; a long wait then 000 means it is blocked.
#Finding a program and where it is
command -v kubectlcommand -v kubectlGet-Command kubectl | Select-Object -ExpandProperty SourceUse this when the wrong version runs: it shows which file the shell actually starts. On Windows, where.exe kubectl lists every match on PATH, in order.
#Searching output
| bash, zsh | PowerShell |
|---|---|
kubectl get pods | grep cms |
kubectl get pods | Select-String cms |
... | head -n 20 |
... | Select-Object -First 20 |
... | tail -n 20 |
... | Select-Object -Last 20 |
wc -l file |
(Get-Content file).Count |
#Paths and folders
| Linux | macOS | Windows | |
|---|---|---|---|
| Home | ~ = /home/<you> |
~ = /Users/<you> |
~ or $HOME = C:\Users\<you> (%USERPROFILE%) |
| AWS config | ~/.aws/ |
~/.aws/ |
$HOME\.aws\ |
| kubeconfig | ~/.kube/config |
~/.kube/config |
$HOME\.kube\config |
| Git config | ~/.gitconfig |
~/.gitconfig |
$HOME\.gitconfig |
| Temp | /tmp |
$TMPDIR |
$env:TEMP |
| Path separator | / |
/ |
\ (PowerShell also accepts /) |
Git Bash's view of C:\Users\you |
/c/Users/you |
#Git Bash rewrites paths that start with /
Git Bash (MSYS) converts arguments that look like Unix paths into Windows paths before running a Windows program. docker exec <container> ls /repo becomes ls C:/Program Files/Git/repo inside the container and fails. Either run such commands in PowerShell, or switch the conversion off for one command:
MSYS_NO_PATHCONV=1 docker compose -f local/docker-compose.yml --profile jenkins exec jenkins git ls-remote -- file:///repo refs/heads/mainThe same applies to kubectl cp and kubectl exec paths such as /bundle/data-bundle.
#If it goes wrong
| What you see | Cause | Fix |
|---|---|---|
curl : A parameter cannot be found that matches parameter name 's' |
PowerShell's curl alias |
Type curl.exe |
'export' is not recognized |
A bash command in PowerShell | Use the Windows tab, or $env:NAME = "value" |
The term 'openssl' is not recognized |
PowerShell has no openssl | Run it in Git Bash |
Error parsing parameter '--parameters': Invalid JSON on Windows |
PowerShell 5.1 dropped the inner quotes | Use file://params.json or the shorthand syntax |
| A JSON or YAML file you wrote "looks fine" but tools say it is invalid | Written by PowerShell 5.1 as UTF-16 | Rewrite it with Set-Content -Encoding ascii or save as UTF-8 in an editor |
Cannot invoke method. Method invocation is supported only on core types in this language mode. |
Constrained Language Mode | Use the Git Bash way, or ask IT |
A path like C:/Program Files/Git/repo appears in an error |
Git Bash path conversion | MSYS_NO_PATHCONV=1 before the command, or use PowerShell |
running scripts is disabled on this system |
PowerShell execution policy | Nothing on this site needs a .ps1; run the command directly or use Set-ExecutionPolicy -Scope CurrentUser RemoteSigned if your IT allows it |
#Sources
kims-deploy-info/shared/prerequisites.md(PowerShell and red output)kims-deploy-info/scripts/README.md(Constrained Language Mode on the engineer's laptop)kims-deploy-info/local/06-jenkins.md,local/07-kubernetes.md(Git Bash path rewriting, Git Bash for.env.localvalues)- https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes
- https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing
- https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows
- https://learn.microsoft.com/en-us/windows/wsl/filesystems
- https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html
- https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-shorthand.html
- https://docs.docker.com/desktop/features/wsl/