Custom Script Directories Included in $PATH

April 6, 2026

This is a short script that will be run whenever /etc/profile is sourced. We will create a directory SCRIPT_DIR that can contain nested directories all of which will be included in the system PATH variable. By design, a local-$HOSTNAME directory with be created to hold scripts specific to this server. Other directories can be made and maintained with git so you can have consistent scripts available across your network similar to system-wide aliases.

/etc/profile.d/05-custom-scripts.sh

#!/bin/bash

SCRIPT_DIR="/usr/src/scripts.d"

mkdir -p "$SCRIPT_DIR/local-$HOSTNAME/"

for d in $(find "$SCRIPT_DIR" -not -iwholename "*/.git*" -not -iwholename "$SCRIPT_DIR" -type d) "$SCRIPT_DIR"
do
  # check if in path
  [[ ":$PATH:" != *":$d:"* ]] && PATH="$d:${PATH}"
done

Now just make it executable, source it, and see that the directory was created as expected.

chmod 755 /etc/profile.d/05-custom-scripts.sh
source /etc/profile
ls /usr/src/scripts.d/

You should see a new directory to keep your custom scripts. Congrats!