HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- global variable ?
Operating System - HP-UX
1839550
Members
2378
Online
110147
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 08:37 AM
01-23-2004 08:37 AM
Hi,
I have a series of shell in /workdir and in each of them I'm using same variable declaring it in each script.
Is there any way to define it ounce and make accesible for all shells.
THankss
Mario
I have a series of shell in /workdir and in each of them I'm using same variable declaring it in each script.
Is there any way to define it ounce and make accesible for all shells.
THankss
Mario
beer or not beer
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 08:44 AM
01-23-2004 08:44 AM
Solution
Hi Mario,
Yes. What you can do it create one shell script that has all the variables and source-it in from your script. For ex.,
script.rc is as follows
#!/usr/bin/ksh
DATE=$(date)
VAR1="variable 1"
VAR2="variable 2"
LOG="/mydir/mylog"
print_line()
{
echo "$DATE: $LINE" >> $LOG
}
Write your scripts and source-in the above. You can even call teh functions as defined above.
script1:
#!/usr/bin/ksh
. /mydir/script.rc
echo my VAR1 is $VAR1
print_line "test line"
You can form other shell scripts in the same way.
-Sri
Yes. What you can do it create one shell script that has all the variables and source-it in from your script. For ex.,
script.rc is as follows
#!/usr/bin/ksh
DATE=$(date)
VAR1="variable 1"
VAR2="variable 2"
LOG="/mydir/mylog"
print_line()
{
echo "$DATE: $LINE" >> $LOG
}
Write your scripts and source-in the above. You can even call teh functions as defined above.
script1:
#!/usr/bin/ksh
. /mydir/script.rc
echo my VAR1 is $VAR1
print_line "test line"
You can form other shell scripts in the same way.
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 08:48 AM
01-23-2004 08:48 AM
Re: global variable ?
Not as the question is stated. One of the most important concepts of UNIX is that no child may alter the environment of its parent process. You could have a parent process set and export some variable and spawn many children and they would all inherit the variable.
The typical answer to your problem is the . (dot) command. It is used to copy a script into a currently running script; it is not a child process.
For example, create a file call myvars.sh:
VAR1="tom"
VAR2="dick"
VAR3="${VAR1}:${VAR2}"
Now each of your scripts could include myvars.sh:
. myvars.sh
echo "Var1 = ${VAR1}"
echo "Var3 = ${VAR3}"
NOTE: Do not put any exit or return statements in myvars.sh or the foreground process will terminate.
The typical answer to your problem is the . (dot) command. It is used to copy a script into a currently running script; it is not a child process.
For example, create a file call myvars.sh:
VAR1="tom"
VAR2="dick"
VAR3="${VAR1}:${VAR2}"
Now each of your scripts could include myvars.sh:
. myvars.sh
echo "Var1 = ${VAR1}"
echo "Var3 = ${VAR3}"
NOTE: Do not put any exit or return statements in myvars.sh or the foreground process will terminate.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 09:11 AM
01-23-2004 09:11 AM
Re: global variable ?
Sourcing a resource file is a common way, as mentioned already.
Another, if it's a variable you need for most of your scripts,
is simply to set and export the variable in your .profile.
(Particularly if these scripts will always be run as the same user)
Another, if it's a variable you need for most of your scripts,
is simply to set and export the variable in your .profile.
(Particularly if these scripts will always be run as the same user)
Not without 2 backups and an Ignite image!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP