[PATCH 2/4] base-files/functions.sh: do not iterate over ls
Rosen Penev
rosenp at gmail.com
Fri Sep 25 22:22:25 EDT 2020
On Sun, Sep 20, 2020 at 3:15 AM <edgar.soldin at web.de> wrote:
>
> On 20.09.2020 07:31, Rosen Penev wrote:
> > - for file in $(ls $1/*.sh 2>/dev/null); do
> > - . $file
> > + for file in "$1"/*.sh; do
> > + [ -e "$file" ] || break
> > + . "$file"
>
> the existence check is probably meant to catch "../*.sh" entry found if no files match. as files will likely not vanish during the loop this will probably work.
> still it'll break the loop completely without any need. using 'continue' instead of 'break' would not break the loop and be safer here.
I was confused on this.
https://github.com/koalaman/shellcheck/wiki/SC2045 lists break.
http://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_.2A.mp3.29
lists continue. I'll make the change.
>
> ..ede
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list