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.
bash
, but your shebang line targetssh
, and you're using (only)sh
-compatible syntax.;
to terminate statements if you place multiple statements on the same line (but note thatdo
andthen
do need a preceding;
if placed on the same line).