![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| bash shell: 'exec', 'eval', 'source' - looking for help to understand | alex_5161 | Shell Programming and Scripting | 3 | 07-24-2008 12:42 PM |
| c shell scripting | bigboizvince | Shell Programming and Scripting | 1 | 03-25-2008 09:33 AM |
| Shell scripting | sreejith | SUN Solaris | 2 | 10-08-2006 09:38 AM |
| difference between AIX shell scripting and Unix shell scripting. | haroonec | Shell Programming and Scripting | 2 | 04-12-2006 08:12 AM |
| shell scripting | anuradr | Shell Programming and Scripting | 1 | 03-08-2006 06:22 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
eval is useful when cmd contains something which needs to be evaluated by the shell. The typical case would be when you have a variable containing the index of an argument you want to access.
Code:
n=1 # or whatever, just to make this self-contained
eval echo \${$n}
|
|
||||
|
Experiment to see.
Code:
vnix$ n=1 vnix$ echo $($n) bash: 1: command not found vnix$ n="date" vnix$ echo $($n) Wed May 21 20:39:00 EEST 2008 Contrast: Code:
vnix$ set -- one two three # sets $1 $2 $3
vnix$ echo $1
one
vnix$ n=1
vnix$ echo ${$n} # attempt to echo $1
bash: ${$n}: bad substitution
vnix$ eval echo \${$n}
one
This is an advanced topic; if you don't have a use for it, don't bother. If you really want to understand this, I suggest you play around with set -x and try different things until you understand what's going on. |
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|