How to get files names passed to a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get files names passed to a script
# 1  
Old 11-06-2007
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.
# 2  
Old 11-06-2007
Code:
for file in $@
do
    echo "$file"
done

# 3  
Old 11-07-2007
The simplest way :
Code:
set -A Files -- "$@"     # First file in Files[0]
set -A Files -- "" "$@"  # First file in Files[1]

Jean-Pierre.
# 4  
Old 11-08-2007
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
# 5  
Old 11-08-2007
A possible solution is to remove the first parameter before filling the array:
Code:
param1=$1
shift
set -A Files -- "$@"

Jean-Pierre.
# 6  
Old 11-08-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading a file passed as an argurement and assessing the files syntax

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (8 Replies)
Discussion started by: Gurdza32
8 Replies

2. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

4. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

5. Shell Programming and Scripting

Script to move files with similar names to folder

I have in directory /media/AUDIO/WAVE many .mp3 files with names like: my filename_01of02.mp3 my filename_02of02.mp3 Your File_01of06.mp3 Your File_02of06.mp3 etc.... In the same directory, /media/AUDIO/WAVE, I have many folders with names like 9780743579490 9780743579491 etc.. Inside... (7 Replies)
Discussion started by: glev2005
7 Replies

6. Shell Programming and Scripting

shell script for ftp files passed in command line argument

i want to write a shell script function that will ftp the files passed in the command line . i have written a shell script for ftp but how will it do for all files passed in command line argument , i am passing 4 files as argument ./ftp.sh file1 file2 file3 file4 code written by me... (5 Replies)
Discussion started by: rateeshkumar
5 Replies

7. Shell Programming and Scripting

Getting the file name passed to a shell script

Hi all I want to use the filename passed into a shell script within the shell it self. The file will be passed as shown below ./myScript < myFile.file i tried $1 but i think since myFile is not passed as a command line arg its not saving the file name in $1 any help is appreciated. (5 Replies)
Discussion started by: sridanu
5 Replies

8. Shell Programming and Scripting

AWK: Retrieving names of variables passed with -v

I'm an experienced awk user, but this one has me stumped. I have an awk script which is called from a UNIX command line as you'd expect: myscript.awk -v foo=$1 -v bar=$2 filename My question is this: is there a mechanism for determining the names of the -v variables within a script? ... (3 Replies)
Discussion started by: John Mac
3 Replies

9. Shell Programming and Scripting

help writing script to read files names

Hi there, I am trying to do somehting similar, but on a wider scale. I am trying to write a script that would open the home directory, open the first (of 650) user's folder open the ?mail directory, which every user has Then I need the script to read each of the files and folder names with... (2 Replies)
Discussion started by: technett
2 Replies

10. UNIX for Advanced & Expert Users

how to configure the lp system to filter files passed to it

I registered a printer hp123 on Sun Solaris Server. I think my printer is expecting a carriage return and linefeed combination at the end of each line (DOS standard), but unix files only have linefeeds at the end of each line. How can I configure the lp system to filter files passed to it?... (1 Reply)
Discussion started by: simt
1 Replies
Login or Register to Ask a Question