Loops in POSIX SH shell

two examples,

/home/x/.shrc
Code:
# Function to safely prepend a directory to PATH if it exists and isn't already there
path_add() {
    if [ -d "$1" ]; then
        case ":$PATH:" in
            *":$1:"*) ;; # Already in PATH
            *) PATH="$1:$PATH" ;;
        esac
    fi
}

export PATH=""

CUSTOM_PATHS="
/home/x/ADA/gnat2022-15.1.1/bin
$JAVA_HOME/bin
/home/x/.local/share/gem/ruby/3.3/bin
/home/x/.local/bin
/home/x/.local/share/coursier/bin
/home/x/.cargo/bin
/home/x/.dotnet/tools
/home/x/.acme.sh
/home/x/.roswell/lisp/quicklisp/bin
/home/x/.nimble/bin
/home/x/git/alire/bin
/home/x/git/DCD/bin
/home/x/git/serve-d
/home/x/git/crystalline/bin
/home/x/git/cppfront/source
/home/x/git/c3-lsp/server/bin
/home/x/git/zls/zig-out/bin
/home/x/git/pony-language-server/build/release
/home/x/git/ols
/home/x/git/clojure-lsp
/home/x/git/zls/zig-out/bin
/home/x/git/clojure-lsp/cli
/home/x/ldc2/ldc2/bin
/home/x/git/Odin
/home/x/config/doomemacs/bin
/usr/local/gnat12/bin
/usr/local/gnat13/bin
/usr/local/gerbil/bin
/usr/local/zig/bin
/usr/local/nim/bin
/home/x/bin
"

for dir in $CUSTOM_PATHS; do
    path_add "$dir"
done

path_add "/usr/local/bin"
path_add "/usr/local/sbin"
path_add "/usr/bin"
path_add "/usr/sbin"
path_add "/usr/local/llvm21/bin"
path_add "/bin"
path_add "/sbin"

export PATH
 
Because we all want to start services in parallel to speed up booting,

/etc/rc.local
Code:
# 2. Define the list of services
SERVICES="
blackbox_exporter
moused
jail
nginx
apache24
minidlna
cupsd
blackbox_exporter
node_exporter
gstat_exporter
telegraf
prometheus
grafana
zabbix74_server
zabbix_agentd
zabbix_server
"

# 3. Loop through and start each service in the background
for srv in $SERVICES; do
    /usr/bin/nohup /usr/sbin/service "$srv" onestart &
done
 
Back
Top