skill-shell-script-hardcoded-paths
Shell script contains hardcoded absolute paths that reduce portability
Rule Details
Hardcoded absolute paths like /Users/john/project or /home/deploy/app make shell scripts non-portable across different systems, users, and environments. This rule scans .sh and .bash files for paths under /Users, /home, /opt, /var, /etc, and /usr/local. Standard system paths like /dev/null, /tmp, /usr/bin/env, and shell paths are excluded. Comments and shebang lines are also skipped. Only one warning per file is reported.
Incorrect
Script with hardcoded home directory path
#!/bin/bash
set -euo pipefail
CONFIG="/Users/john/project/.config"Script referencing a hardcoded /opt path
#!/bin/bash
set -euo pipefail
source /opt/mycompany/scripts/common.shCorrect
Script using environment variables for paths
#!/bin/bash
set -euo pipefail
CONFIG="$HOME/project/.config"Script using relative paths
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/common.sh"How To Fix
Replace hardcoded absolute paths with environment variables like $HOME, $PWD, or $(dirname "$0") for script-relative paths. Use relative paths when possible.
Options
This rule does not have any configuration options.
Related Rules
Resources
Version
Available since: v0.2.0