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
read is not pausing to read davegerdt Shell Programming and Scripting 3 04-07-2008 10:20 AM
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 03:02 PM
Cannot read in variable using read on first try normie UNIX for Advanced & Expert Users 1 10-05-2005 01:42 AM
read line and read next ariuscy UNIX for Dummies Questions & Answers 7 09-21-2005 07:04 AM
read() Deepa IP Networking 1 06-07-2002 08:50 AM

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

Join Date: Jul 2005
Location: Belfast
Posts: 49
While/Read

Hi,

I am trying to read all the files in a directory into an array, in different stages. However the code below:

#Checks the SQL Directory for files to be released

#Do the Packages Specification before the bodies
counter=0

while read packageSpecName
do
packageSpecs[$counter]=`basename $packageSpecName`

counter=$counter+1
done < `ls ${sqlDirectory}/*.pks`


Does not work, it gives an error almost like it is trying to execute the files in the directory instead of save them to the array.

Error:

./release.sh[15]: /usr/home/oracle92/sosa/scripts/rep.pks^J/usr/home/oracle92/sosa/scripts/test.pks: cannot open

Any idea what I am doing wrong?

Thanks
  #2 (permalink)  
Old 05-09-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
if files are read into an array use something like this

Code:
ls | while read line
do
done
  #3 (permalink)  
Old 05-09-2007
LiquidChild LiquidChild is offline
Registered User
  
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Thanks Matrix,

I will give that a go, can you tell me why it would not work on my example above? I would like to understand what I am doing wrong if possible.
  #4 (permalink)  
Old 05-09-2007
LiquidChild LiquidChild is offline
Registered User
  
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Yeah that works, thanks. If anyone know why my solution didn't can you let me know. I like to learn the reasons behind why not to do things!
  #5 (permalink)  
Old 05-09-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Quote:
Originally Posted by LiquidChild
Thanks Matrix,

I will give that a go, can you tell me why it would not work on my example above? I would like to understand what I am doing wrong if possible.

`ls file` expands to the list of selected files

and

done < `ls files`

with the above, while is reading from the selected files and from the list of files
  #6 (permalink)  
Old 05-09-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
for packageSpecName in `ls ${sqlDirectory}/*.pks`
do
...
done
  #7 (permalink)  
Old 05-09-2007
LiquidChild LiquidChild is offline
Registered User
  
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Kinda of the back of this, and not sure if it should be in a seperate post. But if they ls does not find any files I get the following outputted to the screen:

/usr/home/oracle92/sosa/scripts/*.trc: No such file or directory

I would rather it did nothing, is it possible to make a check for files before using the ls? As 'ls' is really the only way I know of doing it.
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 12:27 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