Sponsored Content
Top Forums Shell Programming and Scripting How to evaluate a variable name on LHS of expression? Post 302886943 by Chubler_XL on Tuesday 4th of February 2014 01:08:38 PM
Old 02-04-2014
Yes, there is nothing special about the export command it is just another builtin command that also happens update the value of a variable. The real issue is that variable assignments are treated specially by the shell see "Simple Command Expansion" section of the bash manual.

The main bits of concern are :

Code:
1. The  words  that  the  parser has marked as variable assignments
   (those preceding the command name) and  redirections  are  saved 
   for later processing.

and

Code:
4. The text after the = in each variable assignment undergoes tilde
   expansion, parameter expansion, command substitution, arithmetic
   expansion, and quote removal before being assigned to the  vari-
   able.

So you see no parameter expansion is done on the text before the = (saved at point 1.).
In contrast the text following the export builtin command gets a full set of tilde, parameter, command and arithmetic expansion: giving us our loophole.

Last edited by Chubler_XL; 02-04-2014 at 02:15 PM.. Reason: clean up formatting
These 2 Users Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to get variable to re-evaluate itself?

Probably a simple one. Basically I am retrieving a number from a file - setting a variable against it and then incrementing this by 1 and using this as an entry number in a log file for messages. I need the variable to re-evalute itself each time I call it so I get the latest number in the file -... (1 Reply)
Discussion started by: frustrated1
1 Replies

2. Shell Programming and Scripting

Evaluate the value of a variable?

I have variables: FOO="Text" BAR="FOO" I'd like to be able to evaluate the variable named as the value of $BAR. echo $FOO Text echo $BAR FOO This is what I'd like to do: echo ${$BAR} (this won't work) Text (3 Replies)
Discussion started by: Ilja
3 Replies

3. Shell Programming and Scripting

Evaluate string containing shell variable names

Hello, I have this: #!/usr/bin/ksh V1=ABC str="hello 123;${V1}" eval "echo $str" i get hello 123 /script.sh ABC not found However eval works if $str variable doesn't contain a semicolumn (eg if str="hello 123~${v1}" running the eval statement above would produce (2 Replies)
Discussion started by: endorphin
2 Replies

4. Shell Programming and Scripting

Variable expression and while

hi, i'm reading a file "LISTE_FILE" like : # $LOGCOM * 5 $PRCCOM * 10 and i want to use the file with "while" and having the fields splitted into new variables for treatment : while read LINE do # Ignorer les commentaires un # en premiere position if then... (3 Replies)
Discussion started by: Nicol
3 Replies

5. Shell Programming and Scripting

How to evaluate the value of a variable ?

How to evaluate the value of a variable ? For example: a=var $a=value !!!error happens!!! I want to evaluate var=value, how to realize it? Thanks! ---------- Post updated at 03:37 AM ---------- Previous update was at 02:22 AM ---------- I am using linux bash. a=var $a=value... (4 Replies)
Discussion started by: 915086731
4 Replies

6. Shell Programming and Scripting

Using a variable as a for loop expression

I'm writing a script to merge the xkcd webcomic tiles for comic 1110. So far, I have written about 100 lines, and instead of doing each quadrant of the image separately, I've decided to use functions to do this, repeating for every quadrant and using variables for each quadrant to make the function... (9 Replies)
Discussion started by: jbondhus
9 Replies

7. Shell Programming and Scripting

Trying to execute a expression in a variable

Hi i tried to execute a below script but it is giving execution error rec=ABC,1234,55.00 Colno=2 coldel=, fd='"'$coldel'"' fprint="'"'{print$'$colno'}'"'" colsyn=`echo "echo "$rec "| awk -F"$fd $fprint` echo column syntax is $colsyn colrec=`colsyn` echo column is $colrec (5 Replies)
Discussion started by: ragu.selvaraj
5 Replies

8. Shell Programming and Scripting

Evaluate Variable At Runtime

Hi, I am trying to set a variable that has time the format desired. And my intention is to echo variable (instead of actual date command) everytime I like to echo date. Please take a look at below code. $NOW='' echo $NOW After 5 minutes $echo $NOW Issue here is , I am not... (2 Replies)
Discussion started by: vinay4889
2 Replies

9. Shell Programming and Scripting

Evaluate Expression within awk

I want to create a conditional expression string and pass in an awk script. My script is as below... comm="\$3 == "hello"" awk -F "^T" -v command="${comm}" ' { if ( command ) { print "hye" } }' testBut the statement "if ( command )" always evaluates to true which is not... (5 Replies)
Discussion started by: Saikat123
5 Replies

10. UNIX for Advanced & Expert Users

How to evaluate expression under awk?

I have to display only those subscribers which are in "unconnected state" and the date is 90 days older than today's date. Below command is used for this purpose: cat vfsubscriber_20170817.csv | sed -e 's/^"//' -e '1d' | \ nawk -F '",' '{if ( (substr($11,2,4) == 2017) && ( substr($11,2,8)... (1 Reply)
Discussion started by: dia
1 Replies
TAU_MAPPING_PROFILE_(3) 					  TAU Mapping API					   TAU_MAPPING_PROFILE_(3)

NAME
TAU_MAPPING_PROFILE_TIMER - Declares a mapping timer SYNOPSIS
C/C++: TAU_MAPPING_PROFILE_TIMER(Profiler timer, FunctionInfo *FuncIdVar); DESCRIPTION
TAU_MAPPING_PROFILE_TIMER enables timing of individual statements, instead of complete blocks. It will attribute the time to a higher-level statement. The second argument is the identifier of the statement that is obtained after TAU_MAPPING_OBJECT and TAU_MAPPING_LINK have executed. The timer argument in this macro is any variable that is used subsequently to start and stop the timer. EXAMPLE
C/C++ : template<class LHS,class Op,class RHS,class EvalTag> void ExpressionKernel<LHS,Op,RHS,EvalTag>::run() { TAU_MAPPING_PROFILE_TIMER(timer, TauMapFI); printf("ExpressionKernel::run() this = 4854 ", this); // Just evaluate the expression. TAU_MAPPING_PROFILE_START(timer); KernelEvaluator<EvalTag>().evaluate(lhs_m, op_m, rhs_m); TAU_MAPPING_PROFILE_STOP(); // we could release the locks here instead of in the dtor. } SEE ALSO
TAU_MAPPING_LINK(3), TAU_MAPPING_OBJECT(3), TAU_MAPPING_PROFILE_START(3), TAU_MAPPING_PROFILE_STOP(3) 08/31/2005 TAU_MAPPING_PROFILE_(3)
All times are GMT -4. The time now is 05:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy