× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Pete,



Pete Helgren wrote:

Here is the issue. I would like to define an environment variable that will be used to substitute another value in another variable.


SHORT ANSWER:

You must've (incorrectly) specified something like this:

CLASSPATH='$MY_HOME:$CLASSPATH'


Change it to double-quotes like this:

CLASSPATH="$MY_HOME:$CLASSPATH"


LONG ANSWER:

Some characters have special meanings in Unix shells (including QShell). In your example, the dollar-sign means "insert variable here", there are other special characters, such as spaces that separate different parameters, etc. Quote marks are used to control how these special characters are interpreted by the shell.

There are three types of quote marks:

a) Double-Quotes (sometimes called "weak quotes"). In these, wildcards, single-quotes and spaces are treated literally, but other special characters are still treated specially.

example:
CLASSPATH="/java/global"
MY_HOME=/home/scott
CLASSPATH="$CLASSPATH:$MY_HOME:/another/dir"

would yield:

/java/global:/home/scott:/another/dir

b) Single-Quotes ("strong quotes"). Almost everything is treated literally... (The only exception that comes to mind is the backslash)

example:
MESSAGE='Lemonade costs $1.00'

would yield:
Lemonade costs $1.00

c) Back-Quotes (this looks like a single quote, but it's slanted the opposite direction). This means that whatever's in the string should be run, as a command, and the stdout of the program should be inserted into your variable.

example:
SPLF=`catsplf -j 608553/KLEMSCOT/W6S1 QSYSPRT 17 | grep "Total:"`

the SPLF envvar will contain the line of the spooled file (from the job number, spooled file name, and spooled file number listed above) that contains the word "Total:".

Pretty neat :)

More about Unix quoting here:
http://www.grymoire.com/Unix/Quote.html


Anyway... your issue is that you used single-quotes, which prevent the dollar-sign from being treated as a special character -- so your variable isn't expanded. Using double-quotes lets you expand the variable.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.