Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 380  / 2 Years ago, sun, january 16, 2022, 7:15:22

How can I execute a program (specifically a bash alias) with the default environment variables?



Consider this example:



export test="something I dont want to exist"

alias _xterm='xterm -fn 7x13 -fa "Ubuntu Mono:size=12:antialias=false"'

_xterm


In the spawned xterm instance, the variable $test shouldn't be set.


More From » bash

 Answers
5

You could execute your command in an empty environment:



env -i _xterm





A quick test harness:



$ export TMUX=3
$ bash -c 'echo $TMUX'
3
$ env -i bash -c 'echo $TMUX'
# nothing echos





Preserving $DISPLAY, $USER, etc:



$ env -i bash -c 'echo $DISPLAY'
# nothing
$ env -i DISPLAY=$DISPLAY bash -c 'echo $DISPLAY'
:0





Or you could explicitly exclude just some variables with the env -u option:



$ export TMUX=3
$ env -u TMUX bash -c 'echo $TMUX'
# nothing

[#29078] Sunday, January 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damomnning

Total Points: 422
Total Questions: 90
Total Answers: 106

Location: Mali
Member since Thu, Aug 13, 2020
4 Years ago
damomnning questions
;