I have a requirement where I have to read the names of the sub directories and copy the names to a file. Following is the code that I have written.
for file in $HOME/AutoQA/screenshots/*
do
if [ -d "$file" ];
then
echo "$file" >> $HOME/AutoQA/FailedTestCases.txt
fi
done
Now the above code works almost perfectly but the output that I get is something like
/home/AutoQA/screenshots/1
/home/AutoQA/screenshots/2
......
But I expect it to be as follows
1
2
....
So I need only the names of the sub directories. Here before running the for loop, I dont want to do
cd /home/AutoQA/screenshots/
How can I manage that? Can anyone help?
/to your glob, it will expand to directory names only, removing the need for theifstatement.