Skip to content

Commit 2501cf3

Browse files
committed
Improve _is_sourced check
from docker-library/postgres@d1cc089
1 parent ddf116f commit 2501cf3

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.template.Debian/docker-entrypoint.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ file_env() {
4242
# check to see if this file is being run or sourced from another script
4343
_is_sourced() {
4444
# https://unix.stackexchange.com/a/215279
45-
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
45+
[ "${#FUNCNAME[@]}" -ge 2 ] \
46+
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
47+
&& [ "${FUNCNAME[1]}" = 'source' ]
4648
}
4749

4850
# usage: docker_process_init_files [file [file [...]]]

5.6/docker-entrypoint.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ file_env() {
4242
# check to see if this file is being run or sourced from another script
4343
_is_sourced() {
4444
# https://unix.stackexchange.com/a/215279
45-
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
45+
[ "${#FUNCNAME[@]}" -ge 2 ] \
46+
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
47+
&& [ "${FUNCNAME[1]}" = 'source' ]
4648
}
4749

4850
# usage: docker_process_init_files [file [file [...]]]

5.7/docker-entrypoint.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ file_env() {
4242
# check to see if this file is being run or sourced from another script
4343
_is_sourced() {
4444
# https://unix.stackexchange.com/a/215279
45-
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
45+
[ "${#FUNCNAME[@]}" -ge 2 ] \
46+
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
47+
&& [ "${FUNCNAME[1]}" = 'source' ]
4648
}
4749

4850
# usage: docker_process_init_files [file [file [...]]]

8.0/docker-entrypoint.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ file_env() {
4242
# check to see if this file is being run or sourced from another script
4343
_is_sourced() {
4444
# https://unix.stackexchange.com/a/215279
45-
[ "${FUNCNAME[${#FUNCNAME[@]} - 1]}" == 'source' ]
45+
[ "${#FUNCNAME[@]}" -ge 2 ] \
46+
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
47+
&& [ "${FUNCNAME[1]}" = 'source' ]
4648
}
4749

4850
# usage: docker_process_init_files [file [file [...]]]

0 commit comments

Comments
 (0)