On 04.09.2015 13:55, Karl Palsson wrote: > Jo-Philipp Wich <j...@openwrt.org> wrote: >> Hi. > >>> Why the -e? You only got existing files in the glob above right? > >> Almost. If the directory does not exist or is empty then the glob >> pattern is returned literally, e.g. "echo /tmp/*" will expand to a list >> of files but "echo /does_not_exist/*" will return "/does_not_exist/*" >> literaly so the for-in loop will run once with the literal glob pattern >> as argument, therefore the "-e" test is required. > > So let's -d test the directory instead of -e testing every file just in > case the directory didn't exist? >
On 04.09.2015 13:55, Karl Palsson wrote: > Jo-Philipp Wich <j...@openwrt.org> wrote: >> Hi. > >>> Why the -e? You only got existing files in the glob above right? > >> Almost. If the directory does not exist or is empty then the glob >> pattern is returned literally, e.g. "echo /tmp/*" will expand to a list >> of files but "echo /does_not_exist/*" will return "/does_not_exist/*" >> literaly so the for-in loop will run once with the literal glob pattern >> as argument, therefore the "-e" test is required. > > So let's -d test the directory instead of -e testing every file just in > case the directory didn't exist? > http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29 also explains why you need to test the availability of the found file. essentially shell globbing will return *.sh if no match is found. to circumvent that case you need test -e. ..ede _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel