The UNIX and Linux Forums  

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
I need help with arrays in C Shell domain Shell Programming and Scripting 5 11-19-2008 07:17 AM
Korn Shell Script to find out error in logfile jithu Shell Programming and Scripting 2 04-24-2008 02:12 PM
how to use arrays in c shell hgphsf Shell Programming and Scripting 6 12-14-2007 01:03 PM
Error Handling in Korn Shell scripts bhgopi UNIX for Advanced & Expert Users 4 09-06-2005 06:44 PM
korn shell "loops & arrays" muzica Shell Programming and Scripting 7 09-23-2004 03:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2008
Registered User
 

Join Date: May 2008
Location: India
Posts: 34
Question Error with korn shell - arrays

Hi All

I have a FTP script which FTPs few files into an user folder. I intend to keep track of the folder size before FTP and after FTP and print that once the FTP script is run (a kind of comparison, "Before FTP, "After FTP").

I decided to use kron shells to accomplish this.
Code:
#! /bin/ksh

analyse_folders_pre() {

 # List of directories to check.
 dirNames[0]='bin'
 dirPath[0]='/home/user1/bin'
 dirNoFilesPre[0]=$(ls  ${dirPath[0]} | wc -l | awk '{print $1}')

 idx=0
 while [ $idx -ne 1 ]
 do
    tempSize=0
    dirFileSizePre[$idx]=0
    dirSize=0

    for i in $(ls ${dirPath[0]})
    do
      tempSize=$( ls -l $i | awk '{print $5}')
      ((dirSize=dirSize+tempSize))
    done
    dirFileSizePre[$idx]=$dirSize
    ((idx = idx+1))
 done

} ### End of analyse_pack_rel_pre

 ### Main Script Starts here ###
 # List of directories to check.
 dirNames[0]='bin'
 export dirNames

 dirPath[0]=''
 export dirPath

 dirNoFilesPre[0]=0
 export  dirNoFilesPre

 dirNoFilesPost[0]=0
 export  dirNoFilesPost

 analyse_folders_pre 

 ### Script to FTP
 ftp_files

 analyse_folders_post

 i=0
 while [ $i -ne 1 ]
 do
  echo ${dirNoFilesPre[$i]}
  echo ${dirFileSizePre[$i]}

  echo ${dirNoFilesPost[$i]}
  echo ${dirFileSizePost[$i]}
  ((i=i+1))
 done
But, I am getting the following error.
syntax error at line 8: `dirNoFilesPre[0]=$' unexpected

What might be wrong? Is there any better way to do it?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-21-2008
vidyadhar85's Avatar
Moderator(The Tutor)
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,190
Quote:
dirNoFilesPre[0]=$(ls ${dirPath[0]} | wc -l | awk '{print $1}')

try doing this..

Quote:
dirNoFilesPre[0]=$(`ls ${dirPath[0]} | wc -l | awk '{print $1}'`)
Reply With Quote
  #3 (permalink)  
Old 08-21-2008
Registered User
 

Join Date: May 2008
Location: India
Posts: 34
Same error

Still getting the same error. . .
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 07:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66