I want to create one bash script that takes as argument a directory from the command line and prints all my subdirectories. My script prints all the files that this directory has and does not enter in the if loop. What am I doing wrong and how to fix it?
#!/bin/bash
echo to argv[1] = $1
if [ -e $1 ] #exist the file
then if [ -d $1 ] # is directory
then if [ -r $1 ] #we can read
then for k in $(ls $1) #all the files in the arv[1]
do
echo $k #print all the files of directory
if [ -d $k ]
then echo $k
fi
done
fi
fi
fi