The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to interpret TOP dj_jay_smith UNIX for Dummies Questions & Answers 7 05-23-2009 12:22 PM
Please interpret. supacow UNIX for Dummies Questions & Answers 1 05-30-2008 03:11 AM
How Do We Interpret This ? dummy_needhelp Shell Programming and Scripting 2 10-31-2007 02:07 PM
Riddle - solve it if you can numstr Shell Programming and Scripting 1 08-15-2007 12:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 04-10-2002
i27oak i27oak is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 1
Ksh riddle: interpret variable two times?

exam is a ksh script. In command line I enter: exam 3 param_2 param_3 param_4.

In exam how can I get the value of the parameter which position is specified by the first argument.
Simply doing this DOES NOT work:

offset=$1
value=$$offset

can you figure out any possible way to interpret a variable two times
  #2 (permalink)  
Old 04-11-2002
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
Bit Pusher
  
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
Check out the "shift" command. I think it will do what you are looking for.
  #3 (permalink)  
Old 04-11-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try:
eval value=\$$offset
  #4 (permalink)  
Old 04-11-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
An alternative to shifting the parameters down would be: (oops, posted at same time - gotta be fast to beat Perderabo, even this early in the morning! )
Code:
eval myparm=$"$1"
  #5 (permalink)  
Old 02-22-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
I'd like to correct: last one is not the same!
I've tryed it:
Code:
bash-845:/home/dca0701/develop/src> nn=aa
bash-846:/home/dca0701/develop/src> aa=final
bash-851:/home/dca0701/develop/src> eval dn=\$$nn
bash-852:/home/dca0701/develop/src> echo $dn
final
bash-853:/home/dca0701/develop/src> eval dn=$"$nn"; echo $dn
aa
I do not even understand why it is happened this way?!
First time by 'eval' the $nn should be substituted for 'aa' and '"' should be remuved (as I understand!). So result should be
Code:
dn=$aa
and that by next processing should be as expected! But it prints only aa ?!
-------------------------
Ok, I've get it! It should be little bit different:
Code:
eval dn="$"$nn; echo $dn
Now it is going to result the same!

So: the 'eval' do NOT evaluates value in double quotations or after backslash, but removes that quotations and backslashes!
  #6 (permalink)  
Old 04-28-2009
pooryorick pooryorick is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 3
The details

>So: the 'eval' do NOT evaluates value in double quotations or after backslash, but removes that quotations and backslashes!

Not exactly. Remember, the shell parses the entire line one time before "eval" gets to interpret it. Walking through:

The original line looks like this:

Code:
eval dn="$"$nn; echo $dn
after the shell parses it one time, it looks like this:

Code:
eval dn=$aa; echo final
Since the value of $aa is "final", thats what gets assigned to dn. But notice that $dn already had a value from a previous statement, and it was that value which got expanded into the literal string "final" before eval interpreted the code.

Also note that "$" evaluates to a literal dollar sign, because there is no way the shell can construe it as a variable indicator

further details on my wiki...

Last edited by vbe; 04-29-2009 at 04:18 AM.. Reason: Removed faulty URL (forum conformance...)
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0