Set the PATH in a Session on UNIX-like Operating Systems
export PATH=$PATH:/some/other/directoryThis appends /some/other/directory to the executable search path for the current shell and all its children. The change vanishes when the shell exits — nothing is written to .bashrc, .profile, or /etc/environment.
Variants
# Prepend instead of append (searched first)
export PATH=/some/other/directory:$PATH
# Make it persistent for future Bash sessions
echo 'export PATH=$PATH:/some/other/directory' >> ~/.bashrc
# POSIX-compliant (works in sh, dash, ksh)
PATH=$PATH:/some/other/directory; export PATHSecurity relevance
- Utility: On a foothold, adding a tools directory to PATH lets you call dropped binaries by bare name without typing full paths.
- Attack surface: UNIX resolves unqualified commands by searching PATH in order. A writable directory early in PATH is a classic binary-planting vector — the UNIX cousin of windows-dll-search-order hijacking. If
/tmpor a user-writable directory appears before/usr/binin a service account’s PATH, that’s a privesc finding. - Persistence vs. stealth: A session-only
export PATHleaves no trace in dotfiles; appending to.bashrcpersists but is easily discovered.
Related
- windows-set-path-session — the Windows equivalent
- bash-wildcard-abuse — another PATH-adjacent shell exploitation concern
- unix-file-descriptors — the other fundamental UNIX process abstraction