- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- env var which is not defined yet
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
12-12-2000 09:12 AM
12-12-2000 09:12 AM
env var which is not defined yet
I tried single quotes:
var1='string${var2}'
echo "var2 is not set yet, var1 is: ${var1}"
# the output is: string${var2}
# I expected: string
#
var2="VAR"
echo "now var2 is set, var1 is: ${var1}"
# the output is: string${var2}
# I expected (I want): stringVAR
#
echo "now var2 is set, var1 is: `eval echo ${var1}`"
# this works, but I have no control over all
# the other shell scripts, which use this variable
I thought there was a simple solution... Can you remind me or point me in the right direction, please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2000 09:38 AM
12-12-2000 09:38 AM
Re: env var which is not defined yet
It might help if you explained the problem you are trying to solve. There might well be an easy solution, but accessing the value of an undefined variable isn't it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2000 09:51 AM
12-12-2000 09:51 AM
Re: env var which is not defined yet
For example:-
var2=VAR
var1='string${var2}'
var1 will contain string${var2}
Double quotes allows substitution:-
var2=VAR
var1="string${var2}"
var1 will contain stringVAR
Some more information aboutr what you are trying to achieve would be useful.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2000 09:57 AM
12-12-2000 09:57 AM
Re: env var which is not defined yet
It is true that looking at your problem with the info we have, it can only be done using eval..., and that you cannot use unseted variable (or should not...), so you can test var2 to see if has default value, if not then eval...
Best of all
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2000 10:06 AM
12-12-2000 10:06 AM
Re: env var which is not defined yet
# var1='string${var2}'
# echo $var1
string${var2}
# var2=VAR
# eval echo ${var1}
stringVAR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2000 10:47 PM
12-12-2000 10:47 PM
Re: env var which is not defined yet
It's really bad practice to use a variable which hasn't been defined yet.
I'm afraid that you'll be forced to use 'eval' if you use it anyway.
Could you give us some more information about what you're trying to achieve? There is surely a different way to do what you want.
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2000 02:49 AM
12-13-2000 02:49 AM
Re: env var which is not defined yet
I have a script (a library of functions) which is called by other scripts. At the beginning of this (function library) script, an environment variable is set. As a result of changes in business procedures, this variable needs to be appended with another variable. But this second variable is only set when one of the functions is executed (and of course the whole thing relies on this function to be executed, but that is no problem).
Because the functions are rather complex, I am reluctant to change all the code in the functions (add 'eval') and test all those changes.
I can think of other solutions, e.g. setting the variable inside the function that defines the second variable. But there is a reason why the first variable is set at the top of the script, it changes from time to time and needs to be edited. The second variable is defined by the environment in which the scripts are running, so that one gets its value at runtime.
Using 'eval' in the function that defines the second variable should work, but it did not work when I tried it. I will try that again.
I just asked the question because I thought there was a quick solution using the single quotes. But if it cannot evaluate automatically, I might have to do the hard and dirty work of a Unix system administrator ;-) (that is my job anyway)
Thanks for your help. It is so good to be able to ask a bunch of colleagues and get a quick response.