New to Shell scripting: Can you check it?

I am trying to write a script to get all the html files under a source directory and and for each html file, run a program with html file as an argument. This program generates an output which I need to save as htmlfilename.txt ( right now i was trying to print it on the command line)

SOURCE_DIR=/a/b/c

#location of program
EXE_DIR=/d/f/g

for htmlfile in 'find $SOURCE_DIR \( -name *.html \)';
do
output=$($EXE_DIR/program "$htmlfile");
echo $output;
echo "Printing the expected output" ;
done

What am I doing wrong? I am not getting any output.
Also How do you assign the output of a command to a variable?
And how do you redirect the output to a file with a specific name?

Thanks much in advance!

For a start

Will not produce the result you expect...
use either \.html or ".html"

Using of find is unnecessary, to select the html files you can do something like:

SOURCE_DIR=/a/b/c

#location of program
EXE_DIR=/d/f/g 

for htmlfile in "$SOURCE_DIR"/*.html
do
  output=$("$EXE_DIR"/program "$htmlfile")
  echo "$output"
done

Regards

Thanks Franklin52 and Vbe for the reply.

I was trying to use 'Find' as my My SOURCE_DIR have mulitple directories and which in turn have html and other files. For example:
SOURCE_DIR= /a/b/c
-c has subdirectories h , d, f and g
-subdirectories h and d has few html files
-f and g has more subdirectories and the subdirectories might have html files

----
for htmlfile in "$SOURCE_DIR"/*.html
----
This works only if SOURCE_DIR have html file.

Can you check whats' wrong with my find command?

Thx so much!

Replace this line:

for htmlfile in "$SOURCE_DIR"/*.html

with:

for htmlfile in $(find $SOURCE_DIR -name "*.html")

Regards

Aha, Got the common sense of shell scripting now:) I was trying to do

for htmlfile in 'find $SOURCE_DIR -name *.html '  

So the idea is to get the result return by 'find' in a variable.

for htmlfile in $(find $SOURCE_DIR -name "*.html")

Thanks guys! its really helpful . Now next target is to put all output into txt files with the same name as html files.

output = program "a/b/d/f/123.html"
redirect output to a/b/d/f/123.txt

ok I think I need help here.
I need to redirect the output to a file with the same name and location as html file

for htmlfile in "$SOURCE_DIR"/*.html
do
$($EXE_DIR"/program "$htmlfile") >> output file
## where putput file = htmlfile.txt""
echo "$output"
doneWhat should I use to create the name of the output file similar to html file?
Can I use sed to copy the location and name of .html file and create a new .txt file with the same name and at the same location?

For example:
output=program "a/b/d/f/123.html"
redirect output to a/b/d/f/123.txt

thx!!

Why want to copy?
Is there a reason why you cannot directly output to the file, to the correct location
e.g. >>$EXE_DIR/$htmlfile.txt

take note of spaces in filenames when using the for loop with find. you can work around by changing IFS, do some quoting, or simply use the while read loop instead

find ..... | while read FILE
do
  # do something with $FILE
done

Vbe
I cant directly output in a file as $htmlfile has a extension of .html ( for example it $htmlfile = a/b/c/d/123.html ) , I need to create a .txt file with the same name and on the same location, so I want a/b/c/d/123.txt

"So the output of a/b/c/d/123.html should go to a/b/c/d/123.txt"

if i use
>>$EXE_DIR/$htmlfile.txt

the name of the file will be a/b/c/d/123.html.txt
isn't it?

Thanks!
--------------
vbe wrote:
Why want to copy?
Is there a reason why you cannot directly output to the file, to the correct location
e.g. >>$EXE_DIR/$htmlfile.txt
1 Day Ago 12:07 AM

Try this:

txtfile=`echo ${htmlfile%.*}.txt`
cp "$htmlfile" "$txtfile"

Posix shell (ksh, bash, etc) can work with strings, what you are trying to do can be done using ${%patterrn} notation

Here is a small example:

 
find /opt/K/SCO/COMMUNICATOR -name "*.htm" |while read f; do 
s=${f%\.*}".txt";
echo "Old: " ${f};
echo "New: " ${s};
done

I am escaping '.' with \. as the '.' itself is spec char for shell.

Reslult:

Old: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/picsfail.htm
New: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/picsfail.txt
Old: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/NSHIfrm.htm
New: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/NSHIfrm.txt
...