Wednesday, April 22, 2015

Shell: loop through multiple files and pass them to the script

Short intro

Script file ./main.sh - bash script, doing the htm/html file processing. HTML - is a folder name. Problem: pass all the htm files to the script file as parameters for processing.

Passing files as parameters

# cd HTML
# ll
-rwxr-xr-x 1 oracle root   25828 Apr 13 15:03 filter
-rwxr-xr-x 1 oracle root    9955 Apr 13 15:03 filter.c
-rw-r--r-- 1 oracle root    2142 Apr 22 08:37 loader.ctl
-rw-r--r-- 1 oracle root    9792 Apr 22 08:46 loader.log
-rwxr-xr-x 1 oracle root    2648 Apr 22 10:04 main.sh
-rw-r--r-- 1 root root     781 Apr 22 09:49 10L31JKYRF5UH4.htm
-rw-r--r-- 1 root root     641 Apr 22 09:49 10L31JUKER1WP1.htm
-rw-r--r-- 1 root root     904 Apr 22 09:49 10L31JULIT5LI3.htm
-rw-r--r-- 1 root root     858 Apr 22 09:49 10L31JUOER5GT3.htm
-rw-r--r-- 1 root root     683 Apr 22 09:49 10L31JUPEM9TH9.htm
........................
# for FILE in *.htm; do ./main.sh $FILE; done;

No comments: