|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Assigning variables
i have variables RECIPIENTS_DEVL,RECIPIENTS_UACC,RECIPIENTS_PROD i have a case statement to get the phase variable: Code:
case ${WMD_UPHASE1} in
u) WMD_UPHASE4=UACC;;
i) WMD_UPHASE4=DEVL;;
p) WMD_UPHASE4=PROD;;
d) WMD_UPHASE4=DEVL;;
*) WMD_UPHASE4=DEVL;;
esacI am unable to assign like the below: Code:
export RECIPIENT_MAIL_ID=${RECIPIENTS_${WMD_UPHASE4}}error: bad substitution Can you let me know what i am doing wrong here? Last edited by Scrutinizer; 02-05-2013 at 04:53 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try Code:
eval export RECIPIENT_MAIL_ID=\${RECIPIENTS_${WMD_UPHASE4}}eval is potential security risk, you need to control the $WMD_UPHASE4 variable and not read it from user input or an input file that others can change.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
thanks for the reply,
Can you explain what eval does here? and why you put \? why is it a security risk? and if there is any other way you suggest as i need to have this variable from input only. |
|
#4
|
||||
|
||||
|
eval is a two-stage operation, it first concatenates the arguments with spaces in between and then executes the resulting command. The backslash is there to keep the first $-sign from being evaluated before the concatenation phase. The backslash gets removed before the second phase.
If a user is able to control what is in variable $WMD_UPHASE4 then he could have his code executed with the permissions of the user executing the script. A better approach would be the use of arrays. In ksh93 and bash4 that can be associative arrays, which means you could use words as the array index instead of only numbers.. Last edited by Scrutinizer; 02-05-2013 at 06:02 AM.. |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Arun Mishra (02-05-2013) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with reading and assigning variables | wisdom | Shell Programming and Scripting | 6 | 03-17-2011 06:11 AM |
| Assigning variables using awk | posix | UNIX for Dummies Questions & Answers | 2 | 05-06-2010 12:39 AM |
| variables not assigning in a function | mac4rfree | Shell Programming and Scripting | 3 | 07-21-2009 10:41 AM |
| assigning variables to their defaults | clx | UNIX for Advanced & Expert Users | 1 | 04-15-2009 10:22 PM |
| assigning variables | k@ssidy | UNIX for Dummies Questions & Answers | 9 | 06-16-2005 10:20 AM |
|
|