Sponsored Content
Top Forums UNIX for Advanced & Expert Users Variable assignments specified with eval shell built-in Post 302486412 by Scrutinizer on Saturday 8th of January 2011 11:14:08 AM
Old 01-08-2011
Thanks guys.. Mystery solved! I ran it through ksh and dash before but I must have been looking at the wrong thing .... It is a bash-only thing then. I never realized default bash is so much different from POSIX and that you really need to use --posix for it to be compliant (at least the way it is compiled in my distribution)

That'll be item #23 on this list...
Bash POSIX Mode - Bash Reference Manual
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

eval a variable that has a .

Hi, Is there any way that I can eval the following - eval abc.csv=def.csv I am getting the - bash: command not found error. thanks. (3 Replies)
Discussion started by: ttshell
3 Replies

2. Shell Programming and Scripting

How to assign eval value as Variable..

Im facing problem in assigning value of eval array variable as normal variable.. x=0 eval DATA${x}="FJSVcpcu" x=`expr $x + 1` eval DATA${x}="FJSVcsr" if x=0, type -> eval echo \$DATA$x , its give me FJSVcpcu i want assign this value into an variable as variable=`eval echo... (3 Replies)
Discussion started by: neruppu
3 Replies

3. UNIX for Dummies Questions & Answers

built in variable to hold the name of therunning script...

Hi, I have multiple functions that can be called by any shell script. These functions have inbuilt echo statements to logs their activity into a log file. When I run multiple shell scripts that call these functions, they all log into the same log file and I am not able to differentiate which... (2 Replies)
Discussion started by: new_learner
2 Replies

4. Shell Programming and Scripting

Passing eval value to a variable

Hello, I have a script that does an scp to a server and then gets the number of process running on that server, the o/P should be stored in a variable for further processing eval `echo "ssh -q $Infa_user@$host 'csh -c $CMD '"` where CMD="ps -ef | grep -i ${INFA_REPO} | grep -v grep | wc... (2 Replies)
Discussion started by: amit1_x
2 Replies

5. Shell Programming and Scripting

eval and variable assignment

Hi, i have an issue with eval and variable assignment. 1) i have a date value in a variable and that date is part of a filename, var1=20100331 file1=${var1}-D1-0092.xml.zip file2=${var2}-D2-0092.xml.zip file3=${var3}-D3-0092.xml.zip i am passing the above variables to a script via... (11 Replies)
Discussion started by: mohanpadamata
11 Replies

6. Shell Programming and Scripting

assignment to variable from eval command

Hi Gurus, I am having 2 parameters as below parm1=value1 parm2=parm1 I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like : if ]; then do this....... fi could you please suggest... (5 Replies)
Discussion started by: k_vikash
5 Replies

7. Shell Programming and Scripting

awk built-in variable for input file

Hi guys, Does awk have a built-in variable which I can use to display the input file it's currently reading? I'm currently concatenating multiple files using awk and later on do some parsing. But for now, I want to add an extra column in the main output data file - basically putting in the... (3 Replies)
Discussion started by: Det7
3 Replies

8. Shell Programming and Scripting

Newline in my script-built shell variable

Hi all, I'm not exactly a shell script guru, so this is probably a very silly question and I'm not seeing the point, but you know, sometimes it happens... I have this script which adds entries to local arp cache using it to find the corresponding IP address. # export MAC=00:25:90:34:3d:f2... (16 Replies)
Discussion started by: micantox
16 Replies

9. Shell Programming and Scripting

'eval' used in variable assignment

pattern1=book { x=1 eval echo \$pattern$x } book (this is the output) But when I assign a variable to the output of the eval it doesn't work unless I prefix 2 times backslash before $ as shown below. { a=`eval echo \\$pattern$x` echo $a } book Why here twice "\" has to be... (3 Replies)
Discussion started by: ravisingh
3 Replies

10. Shell Programming and Scripting

Safe way to eval variable declarations?

Is there a safe way to evaluate variable declarations within a script whether they come from a .conf file, user input, or stdin? Example .conf file: server=ftp.xxxx.com port=21 user="$USER" # Hopefully allow this type of substitution domain="$DOMAIN" server="$(malicious... (4 Replies)
Discussion started by: Michael Stora
4 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 [argument]... *eval [argument]... ksh93 +exec [-c] [-a name] [command [argument ... ]] +eval [argument]... DESCRIPTION
sh The exec command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments and appear and, if no other arguments are specified, 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 can be nested, but if they are nested too deeply the shell can 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 specified, the command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments can appear and affect the current process. If no arguments are specified the effect of this command is to modify 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 variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ksh93 exec is a special built-in command that can be used to manipulate file descriptors or to replace the current shell with a new command. If command is specified, then the current shell process is replaced by command rather than running command and waiting for it to complete. There is no need to use exec to enhance performance since the shell implicitly uses the exec mechanism internally whenever possible. If no operands are specified, exec can be used to open or close files, or to manipulate file descriptors from 0 to 9 in the current shell environment using the standard redirection mechanism available with all commands. The close-on-exec flags is set on file descriptor numbers greater than 2 that are opened this way so that they are closed when another program is invoked. Because exec is a special command, any failure causes the script that invokes it to exit. This can be prevented by invoking exec from the command utility. exec cannot be invoked from a restricted shell to create files or to open a file for writing or appending. eval is a shell special built-in command that constructs a command by concatenating the arguments together, separating each with a space. The resulting string is taken as input to the shell and evaluated in the current environment. command words are expanded twice, once to construct argument, and again when the shell executes the constructed command. It is not an error if argument is not specified. On this manual page, ksh93 commands that are preceded by one or two + symbols are special built-in commands and 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. They are not valid function names. 5. Words following a command preceded by ++ that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name genera- tion are not performed. OPTIONS
ksh93 The following options are supported by ksh93 exec: -a name argv[0] is set to name for command. -c Clear all environment variables before executions except variable assignments that are part of the current exec command. EXIT STATUS
ksh The following exit values are returned by exec: 0 Successful completion. 1-125 A redirection error occurred. 127 command was not found. 126 command was found, but it is not an executable utility. ksh93 The following exit values are returned by exec. If command is specified, exec does not return. 0 Successful completion. All I/O redirections were successful. >0 An error occurred. The following exit values are returned by eval: If argument is not specified, the exit status is 0. Otherwise, it is the exit status of the command defined by the argument operands. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), ksh(1), ksh93(1), sh(1), attributes(5) SunOS 5.11 8 Apr 2008 exec(1)
All times are GMT -4. The time now is 11:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy