10-18-2012
The first rule about using eval is "don't do that". If you find yourself using eval, you've probably taken a wrong turn somewhere -- your program likely could've been solved in ways which don't need it, usually by representing data in a different way. eval just seems the most obvious since it's a big enough hammer to drive the most stubborn nails, even those ones with strange sharp spirals down their sides (screws, better driven with a screwdriver).
So, how would I do that in shell? I wouldn't. I'd use double-quotes and store the variable contents in the first place -- eval is almost certainly slower than double quotes!
Last edited by Corona688; 10-18-2012 at 12:32 PM..
10 More Discussions You Might Find Interesting
1. UNIX Desktop Questions & Answers
If I want to do high-end 3d animation, what skell scripting languages, and programming languages shoul I learn?
If you know any good resources for learning these languages they would be appreciated. (1 Reply)
Discussion started by: aloysius1001
1 Replies
2. UNIX for Advanced & Expert Users
I have never programmed in Perl (insert laughter, mock, etc. here ____) - so I need a sort of "Programming in Perl" covering the basics.
I now have two Perl books, one is a 5 volume Unix resource kit, the other is "Mastering algorithms with Perl" - none of them explains how to produce "hello,... (11 Replies)
Discussion started by: AtleRamsli
11 Replies
3. News, Links, Events and Announcements
Check the essays out.
http://www.paulgraham.com (0 Replies)
Discussion started by: photon
0 Replies
4. What is on Your Mind?
Can someone suggest any online venues to assist in recruiting a senior C programmer (looking for someone interested in working on kerberos code).
I've tried a bunch of the open source and higher ed lists (this is for Univ. of Michigan). The commercial services such as Dice or monster yield a... (7 Replies)
Discussion started by: painman
7 Replies
5. What is on Your Mind?
Post what languages (including scripting) you know, why and where you think that language is most usable. Also include libraries in which you're really good at (libusb, gtk, qt, etc).
assembly?
C or C++?
perl or python?
pascal?
bash or csh/tcsh?
opengl?
gtk or qt?
mono? (27 Replies)
Discussion started by: redoubtable
27 Replies
6. Shell Programming and Scripting
value of i = solarisbox
ssh $i "cat /etc/hosts | sed "s/$i\.local\.//" | sed "s/$i\./$i/" | sed "s/$i/$i.sol.com/" > /usr/users/chidori/edit_hosts"While running the above one liner its i am not able to make the changes and write it to the file /usr/users/chidori/edit_hosts . I know there is a... (2 Replies)
Discussion started by: chidori
2 Replies
7. Programming
i have MOTIF installed X11
a easy program is saved as hello.c
there is the following message
where can i get the X11/intrinsic.h , file ???
need help to compile
my system : MX-16 Linux Debian Jessie / i386
hans@mx1:~/Documents
$ cc push.c -o push -lXm -lXt -lX11
In file included from... (0 Replies)
Discussion started by: Zabo
0 Replies
8. Forum Support Area for Unregistered Users & Account Problems
When I visit Programmers forum my ESET Nod32 detects TrojanDownloader.Pegel.BH.trojan
I don't know when it started, as I visited the site today after staying off-line a few days. (2 Replies)
Discussion started by: migurus
2 Replies
9. What is on Your Mind?
While working on my current "UNIX history project" I ran across this:
Jerry Saltzer created an online scanned copy of the Multics Systems Programmers' Manual (MSPM) in this directory.
Based on the 1969-04-01 MSPM, the repo comprising 996 PDF files.
In order to help preserver the MSPM, ... (1 Reply)
Discussion started by: Neo
1 Replies
10. What is on Your Mind?
Hi guys and gals...
A mildly humourous blog from 2013, but I come into this category... ;oDD
Languager: The Poorest Computer Users are Programmers (0 Replies)
Discussion started by: wisecracker
0 Replies
exec(1) User Commands exec(1)
NAME
exec, eval, source - shell built-in functions to execute other commands
SYNOPSIS
sh
exec [argument...]
eval [argument...]
csh
exec command
eval argument...
source [-h] name
ksh
*exec [arg...]
*eval [arg...]
DESCRIPTION
sh
The exec command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments may
appear and, if no other arguments are given, cause the shell input/output to be modified.
The arguments to the eval built-in are read as input to the shell and the resulting command(s) executed.
csh
exec executes command in place of the current shell, which terminates.
eval reads its arguments as input to the shell and executes the resulting command(s). This is usually used to execute commands generated as
the result of command or variable substitution.
source reads commands from name. source commands may be nested, but if they are nested too deeply the shell may run out of file descrip-
tors. An error in a sourced file at any level terminates all nested source commands.
-h Place commands from the file name on the history list without executing them.
ksh
With the exec built-in, if arg is given, the command specified by the arguments is executed in place of this shell without creating a new
process. Input/output arguments may appear and affect the current process. If no arguments are given the effect of this command is to mod-
ify file descriptors as prescribed by the input/output redirection list. In this case, any file descriptor numbers greater than 2 that are
opened with this mechanism are closed when invoking another program.
The arguments to eval are read as input to the shell and the resulting command(s) executed.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
EXIT STATUS
For ksh:
If command is not found, the exit status is 127. If command is found, but is not an executable utility, the exit status is 126. If a redi-
rection error occurs, the shell exits with a value in the range 1-125. Otherwise, exec returns a zero exit status.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
csh(1), ksh(1), sh(1), attributes(5)
SunOS 5.10 17 Jul 2002 exec(1)