"$" in environment variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "$" in environment variable
# 1  
Old 11-20-2002
Question "$" in environment variable

Hi,

I have a problem with retreiving the value of an environment variable. The name of the variable is:

DIR$INP

I am not able to change the name of the variable, because it is used by programs to which I do not have access to. The variable contains the name of a directory as value. I have tried many things to access this value on a shell, but I haven't succeeded. I've tried things like:

echo $DIR$INP

echo $DIR\$INP

echo ${DIR\$INP}

echo $'DIR\$INP'

echo $"DIR\$INP"

Nothing seems to work. Can anybody help me please... Thank you,

kind regards,
Lamac
lamac
# 2  
Old 11-20-2002
Re: "$" in environment variable

Quote:
Originally posted by lamac

I have a problem with retreiving the value of an environment variable. The name of the variable is:

DIR$INP
What shell are you using that allows a '$' in a variable name? How does it get set? This looks like a VMS-ism to me --- are you running some program cross platform?

Is this a homework question?
# 3  
Old 11-20-2002
I'm using SunSolaris.

I know, it sounds crazy, it's not my fault. I'm migrating a VAX/VMS (no I'm not 60 years old...) application to UNIX, but I'm not that much aquainted with UNIX. But I do know how to read values from a shell.

The value is set with "setenv", like this:

setenv 'DIR$INP' "$HOME/cart/log"

This works, and I can see the values in the environment. But I can't access the value with $DIR\$INP. I don't get it.
lamac
# 4  
Old 11-20-2002
Quote:
Originally posted by lamac
I'm using SunSolaris.

I know, it sounds crazy, it's not my fault. I'm migrating a VAX/VMS (no I'm not 60 years old...) application to UNIX, but I'm not that much aquainted with UNIX. But I do know how to read values from a shell.

The value is set with "setenv", like this:

setenv 'DIR$INP' "$HOME/cart/log"

This works, and I can see the values in the environment. But I can't access the value with $DIR\$INP. I don't get it.
Okay, you're using csh or tcsh: Both will allow you to set such a variable, but neither will allow you to use it in the shell. If you need the value of this variable at the shell level do something like one of these:
Code:
setenv 'DIR$INP' "$HOME/cart/log"
awk 'BEGIN { print ENVIRON["DIR$INP"] ; exit }'
# a less direct alternative:
env | grep '^DIR$INP' | cut -d= -f2
# or equivalently:
env | awk -F= '/^DIR$INP/ { print $2 }'

At least one of these should work.
# 5  
Old 11-20-2002
Yea,

thanks, the second one works. But what does it do? If it's not too much trouble, coud you just briefly explain??

Thanks,
Mitch
lamac
# 6  
Old 11-20-2002
Quote:
Originally posted by lamac
thanks, the second one works. But what does it do? If it's not too much trouble, coud you just briefly explain??
Okay, assuming you mean this one:
Code:
env | grep '^DIR$INP' | cut -d= -f2

"env" just echoes the entire environment to standard output.

"|" strings the standard output of one command to the standard input of the next; this is called a "pipe" or (as a transitive verb) "piping".

grep (global regular expression print) selects lines from its input according to a specification. Putting the specification in apostrophes prevents expansion of shell variables. Consult the man page for more --- much more!

The result of grep is the piped into "cut". "-d=" tells cut to separate fields by the equal sign, and "-f2" tells it to print the second field.

This solution should probably be changed to
Code:
env | grep '^DIR$INP=' | cut -d= -f2

to prevent the grep from matching on DIR$INPUT_SEQUENCE, DIR$INPUT_METHOD, etc.

NB: I'm surprised that the awk in Solaris doesn't take the first solution ... maybe change "awk" to "nawk"? Consult the man pages to find out why.
# 7  
Old 11-20-2002
Computer

OK, I really got it. Thanks a lot. Great help.

GreetX,
Mitch
lamac
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing To e-mail address and column 3 contains cc e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Solaris

Solaris Operating Environment Installation CD, aka "CD0" PN: 704-7076-10

Hi to all. It is need to install Solaris 2.5.1 on Sun Enterprise 220r and 420r. Share somebody Solaris Operating Environment Installation CD, aka "CD0" PN: 704-7076-10 ... It is very necessary! ! ! PM or ftp link.... :D (4 Replies)
Discussion started by: aivengoff
4 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

if [ "variable" = "numerical-range" ]; then

been a while so i'm a bit rusty and need a little help. writing a script that needs to compare $EXECHOST(a number) against a numerical range and then set a value. below isn't working but should give you folks an idea of my goal: if ; then echo "This is a 32B machine, exiting..." if ;... (4 Replies)
Discussion started by: crimso
4 Replies

7. Shell Programming and Scripting

What is the "NAME" environment variable used for ?

Hi all, I am running Solaris and I just find there is an environment variable called "NAME" set in my .profile. I googled it for a while and still don't know what is this variable used for (I think it is different as USERNAME or USER?)? When I used mailx to send emails to my PC (thought... (4 Replies)
Discussion started by: qiulang
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Advanced & Expert Users

Reset environment - ".. /etc/.environment dev_env"

I have been resently working on some ksh script. One of the line in the file writes: .. /etc/.environment dev_env I can not understand what this mean, all I know is .environment is unix system environment file. Is ".." a command? If some one can give me some clue where can I find information... (7 Replies)
Discussion started by: zzwu3591
7 Replies
Login or Register to Ask a Question