Variables in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variables in unix
# 1  
Old 01-18-2012
Variables in unix

Hi,

I have defined 2 variables in a ksh file something like below.

x=abc
y=x

Now, I want to get abc printed using y.

I have tried echo $"$y" and I am getting $x but where as I am expecting abc.
Please suggest.

(something like pointer pointer in C language)
# 2  
Old 01-18-2012
I think you are looking for something like this using eval:

Code:
#!/usr/dt/bin/dtksh

x=abc
y=x
eval z=\$${y}

print "x: $x"
print "y: $y"
print "z: $z"

# Prove the value of y has not changed:
print "\ny: $y"

exit 0

Output:
Code:
$ evaltest
x: abc
y: x
z: abc

y: x
$

eval scans the line twice, first replacing ${y} with it's value, 'x' so then z is equal to $x.

Last edited by gary_w; 01-18-2012 at 04:18 PM..
# 3  
Old 01-18-2012
Thanks for your reply!!! it works...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing 2 variables in UNIX

Hi, I have 2 variables as given below. How can i compare them and say its matching ? Appreciate your help VAR1=describe/read/write VAR2=read/write/describeThanks, Please use CODE tags as required by forum rules! (4 Replies)
Discussion started by: prince1987
4 Replies

2. UNIX for Beginners Questions & Answers

Setting variables in UNIX

Hi, I am a beginner in Unix. Now I am learning setting up variables. However, I am receiving an error. Can anyone please help me with it My command as Test=unixprogramming returns the error command not found. (I am using FreeBSD Unix and in my terminal, it is ~% instead of $ . is the... (2 Replies)
Discussion started by: kgopan
2 Replies

3. UNIX and Linux Applications

Passing variables from UNIX to Ansible to UNIX shell

I m passing a variable stringg from Unix shell which has value 'Good Day' to ansible and from ansible to a second shell script where it print only Good instead of 'Good Day' passing the variable stringg from unix shell script1.sh echo $stringg ansible-playbook install.yml -i... (1 Reply)
Discussion started by: mohtashims
1 Replies

4. Shell Programming and Scripting

Help with manipulating environmental variables in UNIX

I am wondering if there is away to increment a date in c shell. What I need to do is basic, but I lack the knowledge. I have they following environmental variable in my job scripts setenv YYYY `date '+%Y'` I then set YYYY to be part of my output dataset name: setenv dd_OUTPUTP... (1 Reply)
Discussion started by: jclanc8
1 Replies

5. UNIX for Dummies Questions & Answers

Define variables with UNIX script

oopps! I Meant "Define Variables within a UNIX Script" What would be the best way to define a variable in a unix shell script so anyone who views this script doesn't know what value is assigned to that variable. some other location... a="/usr/lib/fileA" Unix script... sed... (5 Replies)
Discussion started by: macastor
5 Replies

6. Shell Programming and Scripting

unix Library path variables.

Library path variables. I need to know the library rnvironment variable in linux. Ie, I install zlib directory in the custom path /usr/local/mylib and give --enable-zlib in the ffmpeg install, ffmpeg should check for the zlib libraries in the path /usr/local/mylib. Currently it checks /usr/lib... (5 Replies)
Discussion started by: anilcliff
5 Replies

7. Shell Programming and Scripting

Simple unix variables in script

I'm creating a script that asks a user for a variable ex read filename; read numberinput; I also have a bunch of files named file.0 file.1 ... file.55 I'm trying to delete all files (if they exist) about file.$numberinput. Can someone help me out on how to include the variable as part... (6 Replies)
Discussion started by: jenix4545
6 Replies

8. Shell Programming and Scripting

Not able to get result to unix variables

I am trying to get the Srcreccnt and Tgtreccnt from unix files and update the oracle table. But i get the below error: ERROR at line 1: ORA-00936: missing expression update velocity_process_control set SOURCE_RECORD_COUNT=,SOURCE_RECORD_COUNT= where batch_id= * ERROR at line 1:... (8 Replies)
Discussion started by: vsmeruga
8 Replies

9. UNIX for Dummies Questions & Answers

Unix passing environmental Variables

In my script when I change an env variable in the parent shell it is only changed for that session - it there away to change it permanently using a script so that when I use rlogin (create a child session) that the env variable is set correctly? Basically what I am trying to do is to pass a... (7 Replies)
Discussion started by: belfastbelle
7 Replies

10. UNIX for Dummies Questions & Answers

comparing 2 string variables in unix

search=Jul 22 date=Jul 22 if then echo They match >>this piece of code does not detect that search and date are equivalent strings.. what's wrong with it? (17 Replies)
Discussion started by: katdaniel16
17 Replies
Login or Register to Ask a Question