Commit 7a82e3fa authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

scripts/setlocalversion: clear local variable to make it work for sh

Geert Uytterhoeven reports a strange side-effect of commit 858805b3
("kbuild: add $(BASH) to run scripts with bash-extension"), which
inserts the contents of a localversion file in the build directory twice.

[Steps to Reproduce]
  $ echo bar > localversion
  $ mkdir build
  $ cd build/
  $ echo foo > localversion
  $ make -s -f ../Makefile defconfig include/config/kernel.release
  $ cat include/config/kernel.release

This comes down to the behavior change of local variables.

The 'man sh' on my Ubuntu machine, where sh is an alias to dash,
explains as follows:
  When a variable is made local, it inherits the initial value and
  exported and readonly flags from the variable with the same name
  in the surrounding scope, if there is one. Otherwise, the variable
  is initially unset.

[Test Code]

  foo ()
          local res
          echo "res: $res"



  $ sh
  res: 1
  $ bash

So, scripts/setlocalversion correctly works only for bash in spite of
its hashbang being #!/bin/sh. Nobody had noticed it before because
CONFIG_SHELL was previously set to bash almost all the time.

Now that CONFIG_SHELL is set to sh, we must write portable and correct
code. I gave the Fixes tag to the commit that uncovered the issue.

Clear the variable 'res' in collect_files() to make it work for sh
(and it also works on distributions where sh is an alias to bash).

Fixes: 858805b3

 ("kbuild: add $(BASH) to run scripts with bash-extension")
Reported-by: default avatarGeert Uytterhoeven <>
Signed-off-by: default avatarMasahiro Yamada <>
Tested-by: default avatarGeert Uytterhoeven <>
parent 82fdd12b
......@@ -126,7 +126,7 @@ scm_version()
local file res
local file res=
for file; do
case "$file" in
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment