When I run the /bin/bash
process with 2 parameters -c
and SomeUserInput
,
where SomeUserInput is echo $TERM
The output is
xterm-256color
Is there a way I can set the value of $TERM via a command line parameter to /bin/bash
so the above invokation of echo $TERM
would print something else that I specify?
(Yes, I've done a lot of digging in man bash
and searching elsewhere, but couldn't find the answer; although I think it's likely there.)
First of all, since you used double quotes, that prints the value of TERM in your current shell, not the bash you invoke. To do that, use /bin/bash -c 'echo $TERM'
.
To set the value of TERM, you can export TERM=linux
before running that command, set it only for that shell with either 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 edit of only using command line parameters to /bin/bash
, you can do that without modifying your input like this:
/bin/bash -c 'TERM=something; eval "$1"' -- 'SomeUserInput'
Well, you can either set the variable on your .bashrc
file, or simply set with the bash invocation:
/bin/bash -c "TERM=something-else; echo $TERM"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With