docker-library / busybox

Docker Official Image packaging for Busybox
http://busybox.net
388 stars 126 forks source link

confused by for loop #181

Closed zffocussss closed 1 year ago

zffocussss commented 1 year ago

https://github.com/docker-library/busybox/blob/164603caaa94899332207e45ca06c1b467108851/apply-templates.sh#L32C1-L50C5

for version; do
....
done

can some guys tell me how this block work,as version is not a array variables.

yosifkit commented 1 year ago

That is shorthand for the following:

for version in "$@"; do

i.e. looping over the args to the script. When the args list is empty in this script, it is set by the eval "set -- $versions" of this block: https://github.com/docker-library/busybox/blob/164603caaa94899332207e45ca06c1b467108851/apply-templates.sh#L16-L19

zffocussss commented 1 year ago

it is so interesting,can you please give me a link to this syntax,as I never used/known about it.

zffocussss commented 1 year ago

what is this meaning ? ${dir////-}

for dir; do
    base="busybox:${dir////-}"
done
tianon commented 1 year ago

it is so interesting,can you please give me a link to this syntax,as I never used/known about it.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_03

what is this meaning ? ${dir////-}

https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion (specifically, ${parameter//pattern/string} - replace all / with -)

zffocussss commented 1 year ago

it is so interesting,can you please give me a link to this syntax,as I never used/known about it.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_03

what is this meaning ? ${dir////-}

https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion (specifically, ${parameter//pattern/string} - replace all / with -)

it do work,thanks @tianon