Hi All, I'm can anyone let me know if there's some variable holding the value of the total number of terminals open. I have a requirement where i need to execute some script only first time a terminal is opened. I feel this is not the right place to post this but will be glad if someone can help me out.
-- cheers Sumatheja Dasararaju
Hi Sumatheja,
I'm guessing you want a script to run only once (did say whether it was per user). You could add your script to the .bashrc file - this way the script would run once when the user logs on. Alternatively run the script and export an environment variable - then check it using an if statement before you run the script again, eg;
if [ -n "$script-has-run-envar" ]; then <source_script> script-has-run-envar="Yes" export $script-has-run-envar fi
Check the lifecycle of the environment variable is what you need though.
Mark
On 29/10/2010 12:26, "sumatheja" sumatheja@gmail.com wrote:
Hi All, I'm can anyone let me know if there's some variable holding the value of the total number of terminals open. I have a requirement where i need to execute some script only first time a terminal is opened. I feel this is not the right place to post this but will be glad if someone can help me out.
-- cheers Sumatheja Dasararaju -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
On 10/29/2010 03:39 PM, Mark Liggett wrote:
Hi Sumatheja,
I’m guessing you want a script to run only once (did say whether it was per user). You could add your script to the .bashrc file – this way the script would run once when the user logs on. Alternatively run the script and export an environment variable – then check it using an if statement before you run the script again, eg;
if [ -n “$script-has-run-envar” ]; then <source_script> script-has-run-envar=”Yes” export $script-has-run-envar
I think you mean -without the $ char- ;-)
export script-has-run-envar
Regards
Whoops - apologies. Friday afternoon :-)
On 29/10/2010 16:26, "Joachim Backess" joachim.backes@rhrk.uni-kl.de wrote:
On 10/29/2010 03:39 PM, Mark Liggett wrote:
Hi Sumatheja,
I¹m guessing you want a script to run only once (did say whether it was per user). You could add your script to the .bashrc file this way the script would run once when the user logs on. Alternatively run the script and export an environment variable then check it using an if statement before you run the script again, eg;
if [ -n ³$script-has-run-envar² ]; then <source_script> script-has-run-envar=²Yes² export $script-has-run-envar
I think you mean -without the $ char- ;-)
export script-has-run-envarRegards
On 29 October 2010 06:39, Mark Liggett mliggett@btisystems.com wrote:
You could add your script to the .bashrc file – this way the script would run once when the user logs on.
I presume you meant ~/.bash_profile ? ~/.bashrc is sourced every time a user opens a terminal, whereas ~/.bash_profile is sourced every time a user logs in. This distinction however becomes redundant when the user always uses a text terminal to login. (as in no gui)
On 29Oct2010 09:52, suvayu ali fatkasuvayu+linux@gmail.com wrote: | On 29 October 2010 06:39, Mark Liggett mliggett@btisystems.com wrote: | > You could add your script to the .bashrc file – this way the script would | > run once when the user logs on. | | I presume you meant ~/.bash_profile ? ~/.bashrc is sourced every time | a user opens a terminal, whereas ~/.bash_profile is sourced every time | a user logs in. This distinction however becomes redundant when the | user always uses a text terminal to login. (as in no gui)
Not if they run a subshell. For example, a shell escape from an editor, or a screen session, or ...
The number of bugs in the .bashrc suggestion is high. $ signs, dahses instead of underscores, .bashrc instead of .bash_profile, presuming the user users bash at all (I don't if I can help it, myself - zsh has better facilities), not working at all anyway, since another login wouldn't see the exported variable anyway, not actually looking at terminals at all...
But the OP needs to clarify what he/she means by "number of open terminals" (for this user? only showing in "who"? or other terminals? etc) and whether that is actaully what they need or just what they think _indicates_ what they actually need.
What he/she actually asks for is difficult to do properly. Hopefully it isn't what they need.
Cheers,