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.
So it uses the value of $n as a command. (It's the same as echo `$n` with backticks.)
Contrast:
See? Now if you assign n=2 it will echo the value of $2, etc. So you can change the name of the variable you are referring to programmatically, dynamically.
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.
Hi all,
some small script with eval turned me to crazy.
my OS is linux
Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux
below script works well
#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls
below... (1 Reply)
Gents,
I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
According to the POSIX specifications eval is a special shell built-in, which should imply that variable assignments specified together with it should remain in effect after the built-in completes. Thus one would expect IFS to be changed after this:
var=$'a\nb c'
$ IFS=$'\n' eval '
for i in... (4 Replies)
I am stuck on something that should really be simple, and was looking for some help..
I am new to shell scripting.Need help on this.....
The script is to find the stale nfs.
cat file
- - - - /abcd/1234
I am writing the script to check the nfs errors of above file
... (3 Replies)
Hi
How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
In POSIX shell, we don't have arrays, but we can iterate over a list like this:
#!/bin/sh
list="Fred Barney Wilma Betty"
for i in $list; do echo $i; done
Fred
Barney
Wilma
Betty
But let's say we want "Mr. Slate" in the list.
We know we can't just stick him in there like this:... (5 Replies)
Hi, experts.
Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) :
exec
eval
source
I've tryed to read the manual pages but did not get much.
Also could not get something useful from Google search - just so much and so not exactly, that is... (3 Replies)