I have defined a variable by writing VAR1='abcd'
into .bashrc
file. I could list the all variables by using compgen -v
command. I could check if any variable from this output by using printenv
or echo $VARIABLE_NAME
commands. This gives the result if this is a system-wide variable or shell/user-wide variable.
How could I check if this is a user-defined variable or shell variable?
Note: Maybe a search could be made in .bashrc
file for the specific variable name. But there maybe a more proper way.
OS: Debian-like Linux (x64), kernel: 4.19.
MYVAR=hello bash -c 'printenv'
, for example) make it really difficult to do anything but guess the origin of a particular variable. – Kusalananda Mar 20 '21 at 09:32