Substitute environment variables in a string:
>>> import os >>> from envsubst import envsubst >>> del os.environ['PS1'] >>> print(envsubst('$USER@$HOST ${PS1:-$}:')) [email protected] $: >>> os.environ['PS1'] = '' >>> print(envsubst('$USER@$HOST ${PS1:-$}:')) [email protected] $: >>> print(envsubst('$USER@$HOST ${PS1-foo}:')) [email protected] : >>> os.environ['DEFAULT_PROMPT'] = '$' >>> print(envsubst('$USER@$HOST ${PS1:-$DEFAULT_PROMPT}:'))
Also supports $0, $1, etc. from argv.