| Author |
Looping through files in a directory (Korn on AIX)
|
|
|
| I have just started programming UNIX on AIX using the Korn shell and I
would be grateful if sample code could be posted to help me achieve
the following:
I have files called-
/home/scripts/main.ksh
/home/scripts/run.ksh
/home/sql/interviews/int1.sql
I would like to have main.ksh read through all the files located in
the same dir as int1.sql (there may be more than 1 file in this dir).
Once main.ksh has the filename it will pass it to run.ksh to do some
processing with it.
Many thanks in advance.
| |
| Trent Buck 2004-11-20, 8:12 am |
| Quoth Craig on or about 2004-11-20:
> I would like to have main.ksh read through all the files located in
> the same dir as int1.sql (there may be more than 1 file in this dir).
>
> Once main.ksh has the filename it will pass it to run.ksh to do some
> processing with it.
If no file contains a space, it's probably safe to say:
for i in /home/sql/interviews/*; do
/home/scripts/run.ksh $i
done
This is safer, but still prone to malicious file naming:
ls /home/sql/interviews \
| xargs /home/scripts/run.ksh
Note that I have used these with a POSIX shell (dash) on Debian. AFAIK
korn is mostly compatible with POSIX, but your mileage may vary.
-trent
PS: `set -e' and `set -x' may be advisable.
| |
| Lőrinczy Zsigmond 2004-11-20, 5:49 pm |
| Trent Buck wrote:
> If no file contains a space, it's probably safe to say:
>
> for i in /home/sql/interviews/*; do
> /home/scripts/run.ksh $i
> done
You may quote the variable:
for i in /home/sql/interviews/*; do
/home/scripts/run.ksh "$i"
done
| |
|
| L?rinczy Zsigmond <nospam@for.me> wrote in message news:<cnnsg2$i4g$1@namru.matavnet.hu>...
> Trent Buck wrote:
>
>
> You may quote the variable:
>
> for i in /home/sql/interviews/*; do
> /home/scripts/run.ksh "$i"
> done
Many thanks for your help, the info has proved very useful.
|
|
|
|