Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active February 12, 2021 18:00
Show Gist options
  • Save turboBasic/49deafee2036dd145928ac2e16e30cce to your computer and use it in GitHub Desktop.
Save turboBasic/49deafee2036dd145928ac2e16e30cce to your computer and use it in GitHub Desktop.
Convert .pam_environment file to shell statements #shell #bash
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC1110,SC2086
if [ -z "$BASH_VERSION" ]; then
echo This file should be executed or sourced by Bash shell
exit 2
fi
perl -pe 's/\\\n/ /' ~/.pam_environment \
| sed --regexp-extended $'
/^#/ d
/^\\s*$/ d
s/@\\{PAM_USER\\}/'"$USER"$'/g
s#@\\{HOME\\}#'"$HOME"$'#g
s/^(\\S+)\\s+DEFAULT=(.+)\\s+OVERRIDE=(.+)$/[ -n "${\\1}" ] \\&\\& export \\1=\\3 || export \\1=\\2/g
s/\\s+DEFAULT=\\s*/=/g
s/\\s+OVERRIDE=\\s*/=/g
/^\\[/! s/^/export /g
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment