can't able to work with eval anyway!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can't able to work with eval anyway!
# 1  
Old 11-09-2011
can't able to work with eval anyway!

my script
Code:
grep -v "^#" ${AP_Config}/masklist_new.txt | while  read system maskleft maskright folder_prd floder_uat datetype Region
do
        if [[ ${env} -eq "PRD" ]]; then
                folder_env="prd"
        else
                folder_env="uat"
        fi
targetfolder=${system}/eval echo \${folder_${folder_env}}
echo $targetfolder
done

Also I tried to assign some variable to eval and then trying call .Still not able to work as below
Code:
newvar=\${folder_${folder_env}}
targetfolder=${system}/eval echo $newvar

It should give the prd folder based on env value from the file.
Can anyone help me out to sort this problem ??
# 2  
Old 11-09-2011
You can't just dump eval in the middle of a string and expect it to do anything when not in backticks.

There's probably better ways to do what you want, depending on your shell. What is it?
# 3  
Old 11-09-2011
it's KSH .
Sorry I didn't get you by dumping eval in middle of the string calculation. Just let me know the better way. I have same config file but depending on env variable I need to pick PRD and UAT column values .

below is my msklist_new.txt file which remains same across the enviroment and if the env variable is PRD then it will pick the values of folder_prd and creates the folder list.
Code:
####################################################################################################################################################
# SYSTEM              MaskLeft                                MaskRight           Folder Prod         Floder UAT          DateType  Region         #
# 20 Char             40 Char                                 20 Char             20 Char             20 Char             10 Char   10 Char        #
####################################################################################################################################################
  su              xpnl_hypo_reu_miplvdone_                .csv                hypopnl             hypopnl             eu        europe
  su             xpnl_hypo_reu_miplvhypo_                .csv                hypopnl             hypopnl             eu        europe
  triss               triss_fxcb_                             .checksum.csv       checksum            checksum            eu        europe
  triss               triss_fxcb_                             .csv                cashbalance         cashbalance         eu        europe

if you think there is better way to do this, please let me know, I will glad to implement.

---------- Post updated at 10:40 AM ---------- Previous update was at 10:02 AM ----------

it's working
I made little change as below
Code:
eval targetfolder=${system}/\$folder_$folder_env

but appreciate if anyone suggest better approch.

Last edited by manas_ranjan; 11-09-2011 at 11:15 AM..
# 4  
Old 11-09-2011
Code:
$ SOMETHING="1234567"
$ VARNAME="SOMETHING"
$ echo "${!VARNAME}"
1234567
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

Eval

thank you (35 Replies)
Discussion started by: ratnalein88
35 Replies

3. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

4. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Help on eval please

Hello All, Since my variables are nested I use eval to populate the data. I have an ambiguity here when eval is used along with & say I have the below variable url="www.unix.com" , this come from function call as argument. I want to take this into another variable say... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

6. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

7. Shell Programming and Scripting

eval

hi all, Am trying to add some code to a ksh script and i dont understand how an eval function is used : _var=$1 _conceal=$2 eval _val=\$${_var} can someone shed some light on what the eval function in the above context means/does ?? thanks. (4 Replies)
Discussion started by: cesarNZ
4 Replies

8. Shell Programming and Scripting

eval help

I am trying to expand the variable $user in my alias command and tried several variations of eval but can't seem to get it to work. The end result should be either: oracle_user='sudo su - oracle ' or oracle_user='sudo su - oracle1 ' user=$(grep '^oracle:' /etc/passwd | cut... (5 Replies)
Discussion started by: BeefStu
5 Replies

9. Shell Programming and Scripting

EVal

Hi All, I'm running some encrypted data through a script I wrote. In order to do this, I'm using eval to resolve some of my variables. At the moment, when I use eval to resolve, it strips out some of my encrypted values, and totally drops some others. For example if I have the value ab1"3 it drops... (1 Reply)
Discussion started by: Khoomfire
1 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question