I know that it can be done using ls -R path
. But I'm trying to learn the syntax and control structures of the shell language, so I'm trying to write my own code:
#!/bin/sh
arg=$1;
lsRec() {
for x in $1*; do
if [ -d "$x" ]; then
lsRec $x;
else
echo "$x";
fi
done
}
lsRec $arg;
When I call the command ./ej2.sh ~/Documents/
, the terminal throws: segmentation fault (core dumped)
. Why I'm getting this error?, Am I missing something in my code?
Thanks.