Last active
February 12, 2021 18:00
-
-
Save turboBasic/49deafee2036dd145928ac2e16e30cce to your computer and use it in GitHub Desktop.
Convert .pam_environment file to shell statements #shell #bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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