Setting a permanent global variable in unix accessible from any script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Setting a permanent global variable in unix accessible from any script
# 1  
Old 09-05-2011
Setting a permanent global variable in unix accessible from any script

Is there anyway in which i can set a permanent global variable in unix, which when initialised with a value and modified during any shell script, would retain its value even if i logout and login

I dont know whether i am being able to express my need clearly but basically what i want is a variable that can be accessed from one script,it may be incremented decremented etc and that the variable would hold its modified value even if i logout and then login and execute the script again

For example if i have a variable x initialised to 10, then if i do x=`expr $x + 1` in one script and then logout and login again, the value of x should be 11
# 2  
Old 09-05-2011
Short answer: no
Long answer: not without a lot of hassle and without guarantees. It might be possible by having the shells logout script (if supported) write the value to a file, which is then read by the login script. BUT you'd have to deal with race conditions, and changes done in a non-login non-interactive subshell (eg. when running a script) would not be picked up without adapting that script first to support these extras.
# 3  
Old 09-05-2011
thanks a lot mate
# 4  
Old 09-06-2011
yes

your global variable is what ever is current in /tmp/myDumpfile.txt
just read it. it may change but if it's in a fixed location the information can either be read by others or given to others.
sample read from file;

#!/bin/sh


echo " READ FROM FILE - LOOP "
while read f
do
echo ""
echo " Doing something cool"
/usr/local/sbin/myshizz.sh
echo " TEST RESULTS for "$f

done < somedata.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to set variable permanent in csh?

We are using csh on our AIX platform, if we have to export/set a specific environment variable we use setenv command but its only valid till session. How do we set that variable permanent in our csh AIX? Do we put it in userprofile file or something else? (1 Reply)
Discussion started by: aixusrsys
1 Replies

2. Shell Programming and Scripting

Can we store a value in temp variable which can accessible?

Hi techies I am trying to write a script which can give me a ATP of a job, My idea is : store a value in a temp variable, next script read the variable in next call of it and give me the diff of values which is ATP, as script is running every hours. Can we do this in Shell Script. If... (5 Replies)
Discussion started by: atul9806
5 Replies

3. Shell Programming and Scripting

Setting a TZ variable in a script

Hello all, I know this must be simple .... but i can't grasp what could be the issue. I'm trying to setup the timezone variable (to the unix command date) according to what i find in a value that i got from parsing the config file. The end result would be setting the log file with this new... (4 Replies)
Discussion started by: maverick72
4 Replies

4. Shell Programming and Scripting

How to make Environment Variable Permanent ??

How can i set a environment variable in unix shell ?? I can set it using setenv or export but when i close & open the terminal again i couldn't see that environment variable, how can i make that change permanent ?? (1 Reply)
Discussion started by: chaditya
1 Replies

5. UNIX for Dummies Questions & Answers

Setting a variable in unix

Hi , Whenever i want to start tomcat server I need to go to <tomcatdir>\bin and execute startup.sh file. How would i make this happen whenever i start my machine? Also want to know How would i set the variable at startup. for example I want to set JAVA_HOME and JRE_HOME whenever the... (3 Replies)
Discussion started by: pinga123
3 Replies

6. UNIX for Dummies Questions & Answers

Unix script to do a global change

I want to write a script to go into a unix directory and recursively change all the instances of a word in every file in every directory and sub directory. Here's where I am now: I can execute find . -print | xargs grep "my_word" to recuresively return all the files with my_word in it. ... (7 Replies)
Discussion started by: progkcp
7 Replies

7. UNIX for Dummies Questions & Answers

setting a global variable in script

Hi All, I know to set global variable i can use export .. But take the situation like below .. I want to set a variable in one script and access that in second script i have done like this .. It is not working one.sh #!/usr/bin/ksh echo $RISSHI export RISSHI=1 two.sh... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

8. Shell Programming and Scripting

Global Variable in a script?

How to create a Global variable within a script file. say i want a varaible called LOGFILE to be used within all the script. how to do that? (2 Replies)
Discussion started by: skyineyes
2 Replies

9. UNIX for Dummies Questions & Answers

setting global variable for all users

hi, i am a newbie unix administrator. i want to set a variable, let's say : alias cls 'clear' But i am not going to add this line in the .login file for every home directory of my 500+ users. pls tell me where should i put this line in, so that all users can use this variable after... (4 Replies)
Discussion started by: champion
4 Replies

10. UNIX for Dummies Questions & Answers

Global PATH setting

I am using Solaris 8 and I want to change the PATH setting for all users. I have edited /etc/profile, but when I log in and check the PATH variable, it hasn't changed. Am I missing something? (5 Replies)
Discussion started by: jxh
5 Replies
Login or Register to Ask a Question