I am learning Linux command and I am practicing and trying to write a basic shell script which list all the files and files in subfolders, like ls *, using recursion.
#!/bin/bash
# list-all: one command to list them all!!!!
listit () {
if [ -d "$1" ]
then
listit "$1"
else
echo "$1"
fi
}
ls | while read items; do
listit "$items"
done
However, the result shows:
./list-all: line 16: 1101 Done ls
1102 Segmentation fault: 11 | while read items; do
listit "$items";
done
Is that because shell doesn't allow recursion? please help, thank you!
ls -Rorfind . type -f?find . -type f