Where should I initialize $BASH_ENV and $ENV?
Greetings dear community,
lately I finished my first LFS (6.6) installation and as I came along the topic 'Bash Startup Files' I stumbled into the $BASH_ENV and $ENV enviroment variables. Well, in the invocation section of the Bash manual pages it is written, that if Bash is invoked non-interactive, it would attempt to read $BASH_ENV (or $ENV if invoked as sh). After noticing these variables are empty in my environment I asked myself the same question as in the title. 1. Where should I initialize $BASH_ENV and $ENV? or 2. Should I initialize these variables at all? 3. If used, what is the default value of these variables? After some research I found the /etc/enviroment file interesting but I am not sure if I should put them there, since always when I am reading something like 'global' or 'for all processes accessible' my stomach starts aching. Maybe I am paranoid, but statements of some experts like you ;) would really ease my mind. Thanks in advance Sam PS: Hope my English is understandable. :) |
Hi,
I'm afraid there is no easy answer to your question. As you already read in the manpage the BASH_ENV variable simply holds the location of a script that will be sourced when bash is executed as a non-interactive shell. This is one way to include some general functionality in all your scripts which are run in a non-interactive shell. So you will have to decide if you need the variable. Here is a very simple example how to utilize BASH_ENV: Create the following text file and save it in /etc/global Code:
echo "'sayItAsItIs' function available!" Code:
BASH_ENV=/etc/global Code:
$ /bin/bash -c 'sayItAsItIs This script has no purpose!' Code:
'sayItAsItIs' function available! Code:
$ cat script.bash I hope this very simple example makes it a bit clearer on how to use these variables. As for your questions: Quote:
If you want different implicit functionality for every user then declare them in their personal ~/.bashrc files. Put the script that is to be sourced in their home directories. Quote:
Quote:
It is probably best to play with those two variables a bit to familiarize yourself with the concept. That's what LFS is there for. E.g., try the following variations of the above command: Code:
$ /bin/bash -c -i 'sayItAsItIs This script has no purpose!' Hope this helps. PS: Quote:
|
Good day,
sorry for my late answer but now, including the examples above, here are my case studies. I wrote an extra script, which determines if a login/interactive bash was started. It is just considering $BASH_ENV since I am interested in non-interactive bash shell behaviour. test.sh: Code:
#!/bin/bash Code:
$ bash --login -ci '. test.sh' |
Quote:
Code:
sh -c 'echo Hello' Code:
sh -c -i 'echo Hello' Just out of curiosity, have you decided whether to use BASH_ENV or not? If yes, what script are you planning to source? |
I wanted to know the behaviour of these variables since the manual page wasn't that clear to me and I hadn't found anything useful. After searching I just got results including the same phrase about these variables as in the bash manual page (in the invocation section) or about the command 'env'.
I read that non-interactive shells use another environment than interactive shells and I want both variations to run the same enviroment. I know not the whole enviroment is another but for example $PS1 is unset in non-interactive mode. I am not sure about this topic and maybe I will write another thread if I won't find anything useful. |
Since there is no reply, I guess this topic is a closed one.
|
All times are GMT -5. The time now is 12:03 PM. |