Skip to content

Instantly share code, notes, and snippets.

@numpde
Created November 6, 2023 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numpde/cd3059c563f20e76157a4982f5a13dff to your computer and use it in GitHub Desktop.
Save numpde/cd3059c563f20e76157a4982f5a13dff to your computer and use it in GitHub Desktop.
Add current path to $PATH
#!/bin/bash
# This script will add the directory where it is located to the PATH
# if it's not already included.
# Get the directory of the current script, regardless of where it's called from
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Check if the directory is already in PATH
if [[ ":$PATH:" != *":$DIR:"* ]]; then
# Add the script directory to PATH for the duration of this session or
# any child processes started from this script
export PATH="$PATH:$DIR"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment