Useful utilities

A set of useful utilities for exploring your setup are collected and shared below.

If your programs don’t run from the command line or generate errors when they run, you’ve probably got an issue with your ENV variables or your PATH.

The commands and script below can help you chase down these errors by helping you print the environment, or list out the PATH variable that is stored in your environment.

Display environment variables

Cut and paste the command into a terminal window.

Get-ChildItem Env: | Sort-Object Name | Format-Table Name, Value -AutoSize
printenv | sort | column -t -s '='
printenv | sort | column -t -s '='

Display listing of path variables

Cut and paste the command into a terminal window.

$env:PATH -split ";"
echo $path | tr ':' '\n'
echo $PATH | tr ':' '\n'

Add these utilities to your shell

Do you like these snippet? Do you have others that you use regularly?

Command shells like powershell, zsh and bash allow users to add their own commands to the shell. See below.

Cut and paste these commands to the your $PROFILE. Freshen the comment as necessary. When done, close and reopen the shell and enter the command listpath and listenv to test.

code $PROFILE
## Aliases added on 10/29/2023 by JL
## The powershell SET-ALIAS function doesn't accept arguments, so we'll use function instead
function ListPath {$env:PATH -split ";"}
function ListEnv {Get-ChildItem Env: | Sort-Object Name | Format-Table Name, Value -AutoSize}

Cut and paste these commands to the your ~/.zshrc. Freshen the comment as necessary. When done, close and reopen the shell and enter the command listpath and listenv to test.

code ~/.zshrc
## Aliases added 10/29/2023 by JL
alias listpath="echo $PATH | tr ':' '\n'"
alias listenv="printenv | sort | column -t -s '='"

Cut and paste these commands to the your ~/.bashrc. Freshen the comment as necessary. When done, close and reopen the shell and enter the command listpath and listenv to test.

code ~/.bashrc
## Aliases added 10/29/2023 by JL
alias listpath="echo $PATH | tr ':' '\n'"
alias listenv="printenv | sort | column -t -s '='"

Editing the environment and PATH variables

Windows provides a nice editor for visually editing your environment and PATH.

Locate the editors using the system menu

Examine both the system and user environments

Sample of my PATH

Safety tips

  1. Manually expand any %APPDATA%, %SYSTEM% or other in the PATH variables. These work with CMD but powershell does not properly expand them.

  2. Remove duplicates.

  3. Be attentive to ORDER. Windows searches for programs following the order of the directories in the PATH and runs the first one it finds.