How can I place a for statement....

In a script?

I have some folders that contain many files of 8MB or more in size. Every day run "for file in F*; do gzip $file; done"

How can I put this in a script to run automatically?

Use an editor like vi, edit a file and insert your commands, use absolute paths as cron might get upset. Then edit the crontab with crontab -e and edit it accordingly. Your cron editor might be vi too.

Imagine someone is searching these forums. They want to put a "for" command in a script. They see a title, "How can I place a for statement..."; how does this help them know if that thread will be helpful for them? What if they search only titles for the words "for" and "script"? Will they find your post?

Please be considerate of others who will come after you (and yourself, if you ever want to find this information if you forget it later!) when choosing your post titles. Others may elect to answer this selfishly-formatted question, but I will not.

Noted.

Now ... to the answer :smiley:

This seemed to have worked:

#!/bin/ksh
for file in /dir/dir2/F*
do
gzip $file
done

I thought that the 'for' statement would've sent the script into a loop or something and wouldn't complete.

No, for just processes a list, and the list in your case are the files being found in with "/dir/dir2/F*".

hrmmmm

the script would be like this

#!/bin/bash
for file in F*; do gzip $file; done

Do you really need a script?

gzip -q /dir/dir2/F*