Sponsored Content
Top Forums UNIX for Advanced & Expert Users Variable assignments specified with eval shell built-in Post 302486390 by Scrutinizer on Saturday 8th of January 2011 06:51:07 AM
Old 01-08-2011
Variable assignments specified with eval shell built-in

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:
Code:
var=$'a\nb c'
$ IFS=$'\n' eval '
for i in $var; do
  echo "$i"
done'
a
b c

But it isn't:
Code:
$ set | grep ^IFS
IFS=$' \t\n'


Last edited by fpmurphy; 01-08-2011 at 11:43 AM.. Reason: fixed link
 

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
command(1)							   User Commands							command(1)

NAME
command - execute a simple command SYNOPSIS
command [-p] command_name [argument...] command [-v | -V] command_name DESCRIPTION
The command utility causes the shell to treat the arguments as a simple command, suppressing the shell function lookup. If the command_name is the same as the name of one of the special built-in utilities, the special properties will not occur. In every other respect, if command_name is not the name of a function, the effect of command (with no options) will be the same as omitting command. The command utility also provides information concerning how a command name will be interpreted by the shell. See -v and -V. OPTIONS
The following options are supported: -p Performs the command search using a default value for PATH that is guaranteed to find all of the standard utilities. -v Writes a string to standard output that indicates the path or command that will be used by the shell, in the current shell execu- tion environment to invoke command_name, but does not invoke command_name. o Utilities, regular built-in utilities, command_names including a slash character, and any implementation-provided functions that are found using the PATH variable will be written as absolute path names. o Shell functions, special built-in utilities, regular built-in utilities not associated with a PATH search, and shell reserved words will be written as just their names. o An alias will be written as a command line that represents its alias definition. o Otherwise, no output will be written and the exit status will reflect that the name was not found. -V Writes a string to standard output that indicates how the name given in the command_name operand will be interpreted by the shell, in the current shell execution environment, but does not invoke command_name. Although the format of this string is unspecified, it will indicate in which of the following categories command_name falls and include the information stated: o Utilities, regular built-in utilities, and any implementation-provided functions that are found using the PATH variable will be identified as such and include the absolute path name in the string. o Other shell functions will be identified as functions. o Aliases will be identified as aliases and their definitions will be included in the string. o Special built-in utilities will be identified as special built-in utilities. o Regular built-in utilities not associated with a PATH search will be identified as regular built-in utilities. o Shell reserved words will be identified as reserved words. OPERANDS
The following operands are supported: argument One of the strings treated as an argument to command_name. command_name The name of a utility or a special built-in utility. EXAMPLES
Example 1: Making a version of cd that always prints out the new working directory exactly once cd() { command cd "$@" >/dev/null pwd } Example 2: Starting off a ``secure shell script'' in which the script avoids being spoofed by its parent IFS=' ' # The preceding value should be <space><tab><newline>. # Set IFS to its default value. unalias -a # Unset all possible aliases. # Note that unalias is escaped to prevent an alias # being used for unalias. unset -f command # Ensure command is not a user function. PATH="$(command -p getconf _CS_PATH):$PATH" # Put on a reliable PATH prefix. # ... At this point, given correct permissions on the directories called by PATH, the script has the ability to ensure that any utility it calls is the intended one. It is being very cautious because it assumes that implementation extensions may be present that would allow user func- tions to exist when it is invoked. This capability is not specified by this document, but it is not prohibited as an extension. For exam- ple, the ENV variable precedes the invocation of the script with a user startup script. Such a script could define functions to spoof the application. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of command: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH. PATH Determine the search path used during the command search, except as described under the -p option. EXIT STATUS
When the -v or -V options are specified, the following exit values are returned: 0 Successful completion. >0 The command_name could not be found or an error occurred. Otherwise, the following exit values are returned: 126 The utility specified by command_name was found but could not be invoked. 127 An error occurred in the command utility or the utility specified by command_name could not be found. Otherwise, the exit status of command will be that of the simple command specified by the arguments to command. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
sh(1), type(1), attributes(5), environ(5), standards(5) SunOS 5.10 17 Jul 2002 command(1)
All times are GMT -4. The time now is 04:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy