Skip to contentSkip to conversation

New GSoC microproject ideas

DISCUSSION Michael Haggerty 4 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#1 lore raw

Here is another, as I seem to have managed to kill another one ;-)

-- >8 --

"VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself, but we cannot do the same with a shell function (most notably, "test_must_fail"); we have subshell invocations with multiple lines like this:

	... &&
	(
        	VAR=VAL &&
                export VAR &&
                test_must_fail git command
	) &&
        ...

but that could be expressed as

	... &&
        test_must_fail env VAR=VAL git comand &&
	...

Find and shorten such constructs in existing test scripts.

#2 lore raw
Quoted 8 lines · Junio C Hamano

Here is another, as I seem to have managed to kill another one ;-)

-- >8 --

"VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself, but we cannot do the same with a shell function (most notably, "test_must_fail");

No? bash:

dak@lola:/usr/local/tmp/lilypond$ zippo()
Quoted 4 lines

{
echo $XXX
echo $XXX
}

dak@lola:/usr/local/tmp/lilypond$ XXX=8 zippo
8
8
dak@lola:/usr/local/tmp/lilypond$ /bin/dash
$ zippo()
Quoted 4 lines

{
echo $XXX
echo $XXX
}

$ XXX=8 zippo
8
8
$ 
dak@lola:/usr/local/tmp/lilypond$ /bin/ash
$ zippo()
Quoted 4 lines

{
echo $XXX
echo $XXX
}

$ XXX=8 zippo
8
8
$ 

Seems to work just fine with a set of typical shells.

Signature · 1 line
David Kastrup
#3 lore raw
Quoted 13 lines · David Kastrup
Quoted 8 lines · Junio C Hamano

Here is another, as I seem to have managed to kill another one ;-)

-- >8 --

"VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself, but we cannot do the same with a shell function (most notably, "test_must_fail");

No? bash:

Quoted 8 lines
dak@lola:/usr/local/tmp/lilypond$ zippo()
Quoted 4 lines

{
echo $XXX
echo $XXX
}

dak@lola:/usr/local/tmp/lilypond$ XXX=8 zippo
8
8

Try:

  zippo() {
    echo $XXX
  }
  XXX=8 zippo
  zippo

XXX remains set after the first call under dash (but not bash). I believe "ash" has the same behavior.

-Peff

#4 lore raw
Quoted 26 lines · Jeff King
Quoted 13 lines · David Kastrup
Quoted 8 lines · Junio C Hamano

Here is another, as I seem to have managed to kill another one ;-)

-- >8 --

"VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself, but we cannot do the same with a shell function (most notably, "test_must_fail");

No? bash:

Quoted 8 lines
dak@lola:/usr/local/tmp/lilypond$ zippo()
Quoted 4 lines

{
echo $XXX
echo $XXX
}

dak@lola:/usr/local/tmp/lilypond$ XXX=8 zippo
8
8

Try:

Quoted 8 lines
  zippo() {
    echo $XXX
  }
  XXX=8 zippo
  zippo

XXX remains set after the first call under dash (but not bash). I believe "ash" has the same behavior.

Yes. I would lean towards considering this a bug. But I agree that it does not help.

Signature · 1 line
David Kastrup
#5 lore raw
Quoted 8 lines · David Kastrup
Quoted 8 lines

Try:

  zippo() {
    echo $XXX
  }
  XXX=8 zippo
  zippo
Quoted 5 lines
Quoted 2 lines

XXX remains set after the first call under dash (but not bash). I believe "ash" has the same behavior.

Yes. I would lean towards considering this a bug. But I agree that it does not help.

Dash's behavior is POSIX (and "bash --posix" behaves the same way).

http://article.gmane.org/gmane.comp.version-control.git/137095

-Peff

#6 lore raw
Quoted 13 lines · Jeff King
Quoted 11 lines · David Kastrup
Quoted 10 lines

Try:

  zippo() {
    echo $XXX
  }
  XXX=8 zippo
  zippo

XXX remains set after the first call under dash (but not bash). I believe "ash" has the same behavior.

Quoted 6 lines
Quoted 2 lines

Yes. I would lean towards considering this a bug. But I agree that it does not help.

Dash's behavior is POSIX (and "bash --posix" behaves the same way).

http://article.gmane.org/gmane.comp.version-control.git/137095

In that case I consider it a standard-compliant bug (namely being a serious problem regarding the usefulness of shell functions). Which makes it unlikely to go away. It makes it easier to interpret, say

zippo() {
XXX=$XXX
}

XXX=8 zippo
echo $XXX

as shell functions presumably should be able to assign to shell variables like built-ins do. But that's not really much of an advantage.

The behavior does not make sense to me also with regard to special built-ins. Bash does

dak@lola:/usr/local/tmp/git$ XXX=8 :
dak@lola:/usr/local/tmp/git$ echo $XXX

dak@lola:/usr/local/tmp/git$

And that makes sense to me. Whatever, does not help.

Signature · 1 line
David Kastrup
#7 lore raw
In reply to Junio C Hamano
Quoted 18 lines · Junio C Hamano

Here is another, as I seem to have managed to kill another one ;-)

-- >8 --

"VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself, but we cannot do the same with a shell function (most notably, "test_must_fail"); we have subshell invocations with multiple lines like this:

	... &&
	(
        	VAR=VAL &&
                export VAR &&
                test_must_fail git command
	) &&
        ...
Quoted 7 lines

but that could be expressed as

	... &&
        test_must_fail env VAR=VAL git comand &&
	...

Find and shorten such constructs in existing test scripts.

Thanks; I just added it.

Michael

Signature · 3 lines
Michael Haggerty
[email protected]
http://softwareswirl.blogspot.com/