The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to assign a variable value to array? balamv Shell Programming and Scripting 2 06-06-2008 03:33 AM
compare array contents with file orahi001 UNIX for Dummies Questions & Answers 0 03-25-2008 05:44 PM
i cannot assign float point numbers to an array in solaris naree SUN Solaris 11 02-27-2008 04:06 AM
to assign cut values to an array Syms UNIX for Dummies Questions & Answers 6 10-29-2007 06:42 AM
declare, assign variables using array, counter, loop egkumpe Shell Programming and Scripting 3 08-09-2004 10:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2007
murtaza murtaza is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 31
Can I assign the contents of file into an array?

I am trying to assign the contents of file e.g

ls "$HOME"

into an array. If it is possible then please guide me without using the concept of awk,sed, and perl16

Thanks
  #2 (permalink)  
Old 03-27-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
set -A arr `ls"$HOME"`
  #3 (permalink)  
Old 03-27-2007
murtaza murtaza is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 31
Thanks for reply but this command is giving an error.
  #4 (permalink)  
Old 03-27-2007
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
pls paste here the error message and the task you want to do.what you want to do either assign contents of file to an array or the result of ls command to array.
  #5 (permalink)  
Old 03-27-2007
murtaza murtaza is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 31
I just want the result for ls command to array. Thanks for interest

ds: line 4: set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
  #6 (permalink)  
Old 03-27-2007
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
Do you have korn shell ksh or you are running into some other shell.
pls switch it to korn shell to use arrays.
Code:
#!/usr/bin/ksh
x=`ls skm`
echo $x
set -A look $x
echo ${look[0]}
  #7 (permalink)  
Old 03-27-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by murtaza
I am trying to assign the contents of file e.g

ls "$HOME"

into an array.
[...]

You can do it without "ls":

Code:
$ ls
a  b  c
$ set *
$ echo ${1} # first element
a
$ echo ${2} # second
b
$ echo ${@} # all
a b c
$ echo ${#@} # number of elements
3
$ eval echo \${${#@}} # last element
c
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0