Edit: I fixed the duplicate problem.
Thanks a lot for the hints guys. I kinda got what I wanned:
Code:
#!/bin/bash
FILEPATH="."
function display()
{
ls $FILEPATH | while read FILE;
do
if [ -d $FILE ]; then
printf "\n"
echo "$FILE"
#notice Im not typing $FILEPATH but FILEPATH
FILEPATH="$FILE"
echo "{"
display
echo "}"
printf "\n"
else
echo "$FILE"
fi
done
}
this works perfectly, or at least how I wanned it to work for a min level.
but now if instead of doing:
I want to get info out of this file(ionode, size in bytes, file type and name) using the command stat
Code:
echo " `stat --format='%n,%f,%i,%s' $FILE` "
then it works only for the files where Im running the script from but not for subsequent directories. It says it cant find the file. So I did a:
after my if statement right after I echo the directory so I change my current working directory to this new one but it doesnt seem to work.
I also tried concatenating the FILEPATH
Code:
echo " `stat --format='%n,%f,%i,%s' $FILEPATH/$FILE` "
Any advise about better practices when it comes to bash programming Ill really appreciate it.
thanks in advance