[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shell variable assignments around function invocations
From: |
Bruno Haible |
Subject: |
Re: shell variable assignments around function invocations |
Date: |
Thu, 10 Jul 2008 12:57:10 +0200 |
User-agent: |
KMail/1.5.4 |
Jim Meyering wrote:
> Given that both dash and Solaris 11's /bin/sh didn't accept it, ...
> Here's a proposed work-around:
>
> + export \
> LOCALE_FR='$(LOCALE_FR)' \
> abs_top_builddir='$(abs_top_builddir)' \
> abs_top_srcdir='$(abs_top_srcdir)' \
> @@ -86,7 +87,7 @@ TESTS_ENVIRONMENT = \
> PERL='$(PERL)' \
> REPLACE_GETCWD=$(REPLACE_GETCWD) \
> PATH='$(abs_top_builddir)/src$(PATH_SEPARATOR)'"$$PATH" \
> - shell_or_perl_
> + ; shell_or_perl_
>
> TEST_LOGS = $(TESTS:=.log)
While ash-0.2 and Solaris 10 /bin/sh both print 1 here:
func_return () { (exit $1); }
f () { test $v = "`printenv v`"; func_return $?; }
v=2 f
echo $?
the latter also rejects the POSIX syntax for 'export':
$ export a=b
a=b: is not an identifier
So, while your workaround would fix the problem for ash-0.2, it will still
not work for the Solaris 10 /bin/sh.
Note that the problem in the two shells is different: in Solaris /bin/sh
the variable assignment is not visible at all inside the function, whereas
in ash-0.2 it is visible but not exported. Test code:
func_return () { (exit $1); }
func_test_exported () { v_val=`printenv v`; echo "v unexported: $v"; echo "v
exported: $v_val"; test $v = $v_val; func_return $?; }
unset v; v=2 func_test_exported
ash-0.2:
v unexported: 2
v exported:
test: =: argument expected
Solaris 10 /bin/sh:
v unexported:
v exported: