![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
for file in $@
do
echo "$file"
done
|
|
#3
|
||||
|
||||
|
The simplest way :
Code:
set -A Files -- "$@" # First file in Files[0] set -A Files -- "" "$@" # First file in Files[1] |
|
#4
|
|||
|
|||
|
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
|
||||
|
||||
|
A possible solution is to remove the first parameter before filling the array:
Code:
param1=$1 shift set -A Files -- "$@" |
|
#6
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|