Docker-alpine: 3.6 to 3.7 sourcing in a file in pwd broken.

Created on 28 Dec 2017  路  4Comments  路  Source: gliderlabs/docker-alpine

This is probably an issue with alpine 3.7, so more of a heads up.

mterzo@divine:~/test_alpine$ docker run -it -v ${PWD}:/src alpine:3.6 sh
/ # cat src/file 
FOO="bar"
/ # . src/file
/ # set|grep FOO
FOO='bar'
/ # cd src/
/src # . file
/src # mterzo@divine:~/test_alpine$ docker run -it -v ${PWD}:/src alpine:3.7 sh
/ # . src/file
/ # cd src
/src # . file
sh: .: file: not found
/src # cat file
FOO="bar"

Most helpful comment

I think this is a feature and not a bug. POSIX says:

If _file_ does not contain a \

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot

So to be portable you need to:
sh . ./file

It seems like dash also behaves this way, so this is what a #!/bin/sh script would behave in debian and ubuntu too.

All 4 comments

I think this is a feature and not a bug. POSIX says:

If _file_ does not contain a \

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot

So to be portable you need to:
sh . ./file

It seems like dash also behaves this way, so this is what a #!/bin/sh script would behave in debian and ubuntu too.

Note that non-portable shells, like bash, happily source paths in same dir.
But I think I will start using strict relative paths.

$ docker run --rm -it alpine:3.7
/ # echo "bar=baz" > foo

/ # . foo
/bin/sh: .: foo: not found

/ # apk add --no-cache bash > /dev/null 2>&1
/ # bash

bash-4.4# . foo
bash-4.4# echo $bar
baz

Yup. And I just found in busybox where the ash they removed this behavior.

This is now in 1.27 of busy box, and 1.26 of busybox had "bash" behavior.

commit 2b4c258e74d033b75b7f34bb384290eceb5da8a6
Author: Denys Vlasenko <[email protected]>
Date:   Tue Jan 10 15:18:38 2017 +0100

    ash: revert "make dot command search current directory first"

    Reverts this:
        commit 8ad78e1ec7b2e873953f9f476fb63b5893526c39
        Author: Denis Vlasenko <[email protected]>
        Date:   Sun Feb 15 12:40:30 2009 +0000
        ash: make dot command search current directory first, as bash does.

fwiw: I opened https://github.com/koalaman/shellcheck/issues/1081 for shellcheck to detect non-portable behavior

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rmNyro picture rmNyro  路  3Comments

u6f6o picture u6f6o  路  4Comments

dniku picture dniku  路  4Comments

dinogun picture dinogun  路  3Comments

ncopa picture ncopa  路  4Comments