Interview Prep/Shell Scripting/ShellCheck, debugging, testing, portability and security

Why is passing secrets as command-line arguments a problem?

AdvancedConceptShellCheck, debugging, testing, portability and security
Answer

Any local user can read every process's arguments via ps aux or /proc/PID/cmdline while it runs, and they end up in shell history, set -x traces and audit logs.

mysql -u app -p"$DB_PASS" ...           # visible in ps
MYSQL_PWD="$DB_PASS" mysql -u app ...   # env: readable only by the same user/root
curl -K <(printf 'header = "Authorization: Bearer %s"\n' "$TOKEN") "$url"
docker login -u ci --password-stdin <<<"$REGISTRY_TOKEN"

Prefer stdin (--password-stdin), config files with mode 0600, or file descriptors via process substitution.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on ShellCheck, debugging, testing, portability and security