Confuse on how to use array and eval..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Confuse on how to use array and eval..
# 1  
Old 02-11-2005
Confuse on how to use array and eval..

Hi,
Can anyone advise me on how to use array on Bash? I am really confuse in how eval is link to array... What i wan to do is let say i have an index of an array of 50. Store either 'N' or 'Y' or "NA" in each index. how to i go about doing it.. then lastly how to i print all the values out in a line... Smilie
# 2  
Old 02-11-2005
Code:
bash-2.05b$
bash-2.05b$ declare -a xyz[50]
bash-2.05b$ xyz[4]="y"
bash-2.05b$ xyz[7]="n"
bash-2.05b$ echo ${xyz[4]}
y
bash-2.05b$ k=7
bash-2.05b$ echo ${xyz[k]}
n
bash-2.05b$ xyz[k]=q
bash-2.05b$ echo ${xyz[k]}
q
bash-2.05b$ xyz[22]="na"
bash-2.05b$ echo ${xyz[*]}
y q na
bash-2.05b$

eval is not "a link to array" whatver that means. You don't need that declare, You can just start using the array and it will pop into existence. You can add the [50] to the declare for documentation reasons, but bash ignores it and will grow the array as required.
# 3  
Old 02-14-2005
Hi,
thank you a lot of your reply. Smilie I appreciate a lot

Regards,
valerie.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. HP-UX

Confuse to run scsimgr

Hello folk, I'm trying to study HP-UX by myself. Now I'm reading some stuffs about how to get information about lunpath, lun and etc.. My problem is when I execute scsimgr like this: # scsimgr get_info -H 0/1/2/0.149.0.255.10.11.0 old new if Usage: scsimgr -o old_target_name -n... (1 Reply)
Discussion started by: alfastar
1 Replies

4. 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

5. Shell Programming and Scripting

Using eval to populate an array in the background

Hi. I am trying to populate an array using eval in the background within a function. So this function will create a list of 3 character directories from SVN and store in an array. I want to call this function when the script starts in the background unknown to the user. The problem is that... (2 Replies)
Discussion started by: jmiaebrown
2 Replies

6. 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

7. Shell Programming and Scripting

eval, array, number of elements - couldn't get it

I try to get a number of elements in an array, using dynamic array name. I need the array name to be dynamic. The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number So, say I have the arr 'inf_ln_4': > for (( el=0; el<${#inf_ln_4}; el++ )); do > echo "$el:... (1 Reply)
Discussion started by: alex_5161
1 Replies

8. Shell Programming and Scripting

how to get status array for the commands in eval

I want to get a status code array for the commands in eval. For example, eval "ls abc; ls def; ls $HOME" I want to get the status code for each ls command in eval. Is there any way to make it? Thanks. (2 Replies)
Discussion started by: pankai
2 Replies

9. UNIX for Advanced & Expert Users

Solaris Linux Windows partition confuse

Dear All I tried to follow the instruction in this link: http://multiboot.solaris-x86.org/v/2.html I created all these partitions as mentioned in the link above by using partition commander 9 Fist stage: I installed XP in first partition (hda1)....success. Second stage: Install... (0 Replies)
Discussion started by: zillah
0 Replies
Login or Register to Ask a Question