Unable to set a data to array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to set a data to array
# 1  
Old 11-28-2008
Error Unable to set a data to array

Hi All,

Iam trying to set the value to the array... Still its not happening

Following is the code:

#!/usr/bin/ksh

filenames[0]="x";
filenames[1]="y";
echo $filenames[0];
echo $filenames[1];

O/P:

x[0]
x[1]


Iam expecting
x
y

Can some one help me
# 2  
Old 11-28-2008
Quote:
Originally Posted by kiranlalka
Hi All,

Iam trying to set the value to the array... Still its not happening

Following is the code:

#!/usr/bin/ksh

filenames[0]="x";
filenames[1]="y";
echo $filenames[0];
echo $filenames[1];

O/P:

x[0]
x[1]


Iam expecting
x
y

Can some one help me

Echo was supposed to be

echo ${filenames[0]};
echo ${filenames[1]};
# 3  
Old 11-28-2008
Hammer & Screwdriver Here is the basic format for setting and displaying array values

Pay attention to placement of { } and [ ] characters

Code:
> smile[1]="hi"
> smile[2]="hello"
> echo ${smile[1]}
hi
> echo ${smile[2]}
hello

and also note....
Code:
> echo ${smile[*]}
hi hello

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Unable to set static ip address

Hi All, Am using centos 7 in my vmware workstatio with the bridged network. when run the ifconfig cmd its not at all showing the ip address and pls advise how to set static ip address in my linux box. (1 Reply)
Discussion started by: sarathkumar s
1 Replies

2. Shell Programming and Scripting

Unable to set Global variable outside while loop

Below is my code: count=0 if ... ... else ... find * -prune -type d | sort -r -n | while read d; do count=1 if ; then echo "Count1:$count" ... ... break 2; fi ... done ... fi echo "Count2:$count" (9 Replies)
Discussion started by: mohtashims
9 Replies

3. Shell Programming and Scripting

Unable to set PATH through ksh shell

I'm trying to set path for the current session but it is not doing so. It works perfectly on command line though. #!/usr/bin/ksh PATH=$PATH:/opt/quest/bin Is there any specific way to set path on korn? (3 Replies)
Discussion started by: pjeedu2247
3 Replies

4. Shell Programming and Scripting

Unable to set my PATH variable

Hello All, Hope you can understand my problem from the below code. $ cat ~/.profile PS1=`whoami`@`hostname`':$PWD $ ' export PATH="$PATH:.:/logarchive/utility/util:/usr/sbin:" $ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:.:/usr/sbin: $ echo $SHELL /usr/bin/ksh ... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

5. Shell Programming and Scripting

Unable to set variables in Linux script

Hi, I am pretty new in writing shell script on LINUX, I tried to write the script just like KSH on HP unix but it seems nothing is working. Even assigning variables seems to be not working as KSH on HP unix. Please help in resolving the issues I am facing on LINUX. I have declared variables for... (5 Replies)
Discussion started by: smr.ryl
5 Replies

6. Solaris

Solaris 9 -- unable to set permanent PATH

Hi, I've read forums far and wide trying to learn how to append to my PATH in Solaris 9 and every time I think I am close I discover my system is not configured the same. Its so frustrating because this all stems from a new server I am trying to setup identical to the production machine. (Of... (5 Replies)
Discussion started by: thoraddict
5 Replies

7. UNIX for Dummies Questions & Answers

unable to set user home dir

I created a new user and changed their home directory to /export/home/mydir/ I verified in the passwd file that the home directory is set to the above and that owner of that directory is the new user and yet when I log in as that user I get the following message: No directory! Logging in with... (14 Replies)
Discussion started by: some_one
14 Replies

8. AIX

Unable to set remote printer in AIX

Hi all, I am a beginner in AIX. I am facing a problem with remote printing in AIX. HP laser jet 1320 printer is connected to a printer server (PCI Mini - 100U3), which is configured as remote printer from AIX server. But I am not able to print from the AIX server by using "lp -d... (0 Replies)
Discussion started by: Rainy
0 Replies

9. Linux

DNS unable to set up!!

Hi Experts, I am a newbie like in Linux world, practising Fedora Linux on VMWare but DNS is never set up: Below are my conf files: 1. named.conf options { directory "/var/named"; /* * If there is a firewall between you and nameservers you want * to talk... (4 Replies)
Discussion started by: vikasdh
4 Replies
Login or Register to Ask a Question