loop through files in a directory in shell script

Given a directory and loops through all the visible files.

#!/bin/sh
DIR='/var/log/myapp/'
for FILE in ls "$DIR"*
do
    echo $FILE
done

Loops files in the given directory and prints files with extension .log

#!/bin/sh
DIR='/var/log/myapp/'
for FILE in ls "$DIR"*.log
do
    echo $FILE
done

Search within Codexpedia

Custom Search

Search the entire web

Custom Search