Shell script: For loop unexpected output -
i have requirement have read names of sub directories , copy names file. following code have written.
file in $home/autoqa/screenshots/* if [ -d "$file" ]; echo "$file" >> $home/autoqa/failedtestcases.txt fi done
now above code works output
/home/autoqa/screenshots/1 /home/autoqa/screenshots/2 ......
but expect follows
1 2 ....
so need names of sub directories. here before running loop, dont want
cd /home/autoqa/screenshots/
how can manage that? can help?
replace line
echo "$file" >> $home/autoqa/failedtestcases.txt
with
basename "$file" >> $home/autoqa/failedtestcases.txt
Comments
Post a Comment