Question about enviroment variable.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about enviroment variable.
# 8  
Old 06-24-2015
Code:
abc$123

How do you see this? Do you see it as the letters abc plus the $ character and the numbers 123?
The shell see it as the string "abc', the positional variable deference $1 and the string "23"
Since there's nothing in $1 it assigns to par2 the string "abc23"

Code:
part=abc$xyz

The shell sees the string "abc" and the variable deference $xyz. And it appears that $xyz produces an empty string.
# 9  
Old 06-24-2015
Quote:
Originally Posted by ken6503
when I try
Code:
par2=abc$123
export par2

I got
HTML Code:
abc23
This is what Don said. Let us take apart the right side of the equation:

Code:
abc=> "abc" (literal string)
$1 => "" (because "$1" is not set, i.e. no argument is passed on commandline)
23 => "23" (literal string)

Therefore you get "abc23" with a "nothing" in between "abc" and "23".

Quote:
Originally Posted by ken6503
when trying
Code:
part=abc$xyz
export par2

I got
Code:
abc

Yes, because the difference is: "$xyz" is a legal variable name while "$123" is not. The variable "$xyz" might not be defined and therefore hold no content (which seems to be the case, because it evaluates to nothing), but it is still a legal variables name. "$123" is NOT a legal name, therefore the shell doesn't even try to evaluate it. Instead it uses what could be a legal name ("$1") and treats everything following it as a literal string again.

You could generate the same effect in your second example by surrounding the variables name with curly braces:

Code:
# v=abc${x}yz
# echo $v
abcyz

The same mechanism: "abc" is a literal string, the "$x" (which is empty, so ""), then "yz", which is again a literal string. If "x" is not empty:

Code:
# x=foo
# x=abc${x}yz
# echo $x
abcfooyz

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 10  
Old 06-24-2015
Thanks Don, Aia and Bakunin for your excellent explanation. I fully understand this now.


have a good day.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Killing all the process of a particular enviroment

Hi Folks, I have the below command that will kill all the process of an environment, lets say if I have reached to the location cont directory under which I want to kill multiple process so the command will be .... kill -9 `ps -ef | grep cont | grep -v grep | awk '{print $2}'` Now please... (4 Replies)
Discussion started by: punpun66
4 Replies

2. Shell Programming and Scripting

Variable to command to Variable Question KSH

Hello, First post for Newbie as I am stumped. I need to get certain elements for a specific PID from the ps command. I am attempting to pass the value for the PID I want to retrieve the information for as a variable. When the following is run without using a variable, setting a specific PID,... (3 Replies)
Discussion started by: Coyote270WSM
3 Replies

3. Shell Programming and Scripting

How to pass enviroment variable from csh to Informix sql script

Hello, I have a csh script that creates an environment variable. I want to pass the environment variable(CURR_TABLE_DATE) to an Informix sql script. Here is the csh: #!/bin/csh -f setenv INFORMIXSERVER market3_tcp setenv CURR_TABLE_DATE 20090714 set DATABASE = gm_cdr set SQL_DIR =... (0 Replies)
Discussion started by: jwoj
0 Replies

4. Solaris

Save enviroment variables

I need to save my enviroment variables,specially the $PATH.When I put it on .cshrc at next reboot I lost the configuration.How can avoid this?Thanks (2 Replies)
Discussion started by: bgf0
2 Replies

5. Shell Programming and Scripting

enviroment settings

What are the environment setting during a cron session? I have HP-UX and I want to send the output/file from a script to several e-mail addresses. I want to create an env-var to store the e-mail addresses in my .profile, but I do not know if it will be visible when a script is executed in a cron. (4 Replies)
Discussion started by: ALTRUNVRSOFLN
4 Replies

6. Shell Programming and Scripting

Enviroment Differences script(s)

Im looking for any sample scripts that would output a current environment setup to a file and possibly then take 2 files and list any differences This will allow us to quickly see any differences between environments in case of issue? At a high level this would take Unix Kernel Params,... (2 Replies)
Discussion started by: JoeShmoe
2 Replies

7. Solaris

set enviroment variable..

Hello... I was wondering can anyone explain me how to set up enviroment variable to be permanent... I tryed with setenv but my solaris does not have this command... then I did: export ORACLE_SID=base1 export ORACLE_BASE=/home export ORACLE_HOME=$ORACLE_BASE/oracle/8.1.6 and by... (5 Replies)
Discussion started by: amon
5 Replies

8. UNIX for Dummies Questions & Answers

Enviroment variables...

Hi guys, thanks in advance for this easy answer.... :s Ok I am trying to output the enviroment varable for host in Solaris. I have tried $HOST, $HOST_NAME, $HOSTNAME carn't find it anywhere, does someone want to put me out of my misary and tell me what it is??? :confused: :eek: Thanks... (2 Replies)
Discussion started by: B14speedfreak
2 Replies

9. UNIX for Dummies Questions & Answers

Accessing remote machine via an enviroment variable

Hi. Is it possible to remotely access another unix box via an enviroment variable, on another machine? I am trying to create an environment variable $MIPSDATA which will point to a folder on another machine. I have setup the .rhosts file and got that working on both machines (tested via a... (4 Replies)
Discussion started by: ElCaito
4 Replies

10. UNIX for Dummies Questions & Answers

Help! - How do I compile C++ in UNIX Enviroment?

:confused: Hi, does anyone here know how to compile and run C++ in UNIX environment? I am so desperate! Any help is greatly appreciated. Thanks! (3 Replies)
Discussion started by: Kahuashi
3 Replies
Login or Register to Ask a Question