How to set the $ TERM value to a value when running / bin / bash through the command line?

When I run the /bin/bash process with two options -c and SomeUserInput ,

where SomeUserInput is echo $TERM

Output signal

xterm-256color

Is there a way to set the value of $ TERM using the command line parameter on /bin/bash so that the above echo $TERM link prints something else that I am specifying?

(Yes, I did a lot in man bash and searched elsewhere, but could not find the answer, although I think it is probably there.)

+4
source share
2 answers

First of all, since you used double quotes that print the TERM value in the current shell, not bash, you call. To do this, use /bin/bash -c 'echo $TERM' .

To set the TERM value, you can export TERM=linux before running this command, install it only for this shell using TERM=linux /bin/bash -c 'echo $TERM' (shell expression) or /usr/bin/env TERM=linux /bin/bash -c 'echo $TERM' (execve compatible (as for find -exec)).

Update: As for your editing using only the command line options on /bin/bash , you can do this without changing your input as follows:

 /bin/bash -c 'TERM=something; eval "$1"' -- 'SomeUserInput' 
+6
source

Well, you can either set the variable to your .bashrc , or simply set using the bash command:

 /bin/bash -c "TERM=something-else; echo $TERM" 
+2
source

All Articles