code-dumps/sh/recursion-demo.sh

18 lines
384 B
Bash
Raw Normal View History

2024-10-24 23:09:21 +08:00
#!/bin/bash
# Script to list all files recursively using recursive bash function
function listFileInDir {
find $1 -maxdepth 1 -type f
DirCount=$(find $1 -maxdepth 1 -mindepth 1 -type d | wc -l)
# Recursive case
if [ $DirCount -ge 1 ]; then
find $1 -maxdepth 1 -mindepth 1 -type d | while read d; do
echo Recursing into $d
listFileInDir $d
done
fi
}
listFileInDir $1