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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with script not able to take parameters passed to it dsravan Shell Programming and Scripting 3 02-28-2008 02:09 PM
Problem with script not able to take parameters passed to it dsravan Shell Programming and Scripting 7 10-09-2007 06:28 PM
checking parameter values passed to script ammu UNIX for Dummies Questions & Answers 2 10-05-2007 09:35 AM
help writing script to read files names technett Shell Programming and Scripting 2 04-26-2005 01:24 PM
how to configure the lp system to filter files passed to it simt UNIX for Advanced & Expert Users 1 09-23-2003 12:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-06-2007
Registered User
 

Join Date: Oct 2007
Posts: 11
How to get files names passed to a script

I need to get files names passed to a script. Here number of files passed may vary
like MyScript.ksh file1 file2 file3..... so on

I am writting script somthing like this

set -A Files

while (i<=$#)
do
File[i]=$i
let i=i+1
done

Is this correct way doing this. Is there any other way.
Please let me know

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 11-06-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Code:
for file in $@
do
    echo "$file"
done
Reply With Quote
  #3  
Old 11-07-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
The simplest way :
Code:
set -A Files -- "$@"     # First file in Files[0]
set -A Files -- "" "$@"  # First file in Files[1]
Jean-Pierre.
Reply With Quote
  #4  
Old 11-07-2007
Registered User
 

Join Date: Oct 2007
Posts: 11
Thanks for your reply. This is really useful.
What I should do if want all parameter passed except first one in array.
Pls let me know.

Thanks
Unishiv
Reply With Quote
  #5  
Old 11-08-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
A possible solution is to remove the first parameter before filling the array:
Code:
param1=$1
shift
set -A Files -- "$@"
Jean-Pierre.
Reply With Quote
  #6  
Old 11-08-2007
Registered User
 

Join Date: Nov 2007
Posts: 13
I am not clear that much, however what I've understood, you need to modify your program a little .........

set -A Files
let i=2
while (i<=$#)
do
File[i]=$i
let i=i+1
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0