Bash Loop File or Directory by Name

This is a simple method how to list file or directory with bash programming :

#!/bin/sh

DIR_LOC=/home/toto
for i in $DIR_LOC/*
do
	echo "Process file $i"
done

If we want to filter ouput data (example : we want to filter list file with *.sh tipe data, so we can change code with :

#!/bin/sh

DIR_LOC=/home/toto
for i in $DIR_LOC/*.sh
do
	echo "Process file $i"
done
4 Comments

Add a Comment

Your email address will not be published. Required fields are marked *