threads / patch / 36080

patch*.sh: drop useless use of "env"

Subject: [PATCH] *.sh: drop useless use of "env"

## tl;dr

2 messages between Mar 6, 2014 and Mar 7, 2014. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Junio C Hamano· Mar 6, 2014, 23:20 UTC · lore

In a bourne shell script, "VAR=VAL command" is sufficient to run 'command' with environment variable VAR set to value VAL without affecting the environment of the shell itself; there is no reason to say "env VAR=VAL command".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Just something I noticed while reading existing tests...
 t/t1020-subdirectory.sh | 2 +-
 t/t9001-send-email.sh   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Show changes to 2 files +2 −2

t/t1020-subdirectory.sh, t/t9001-send-email.sh

diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index 1e2945e..6902320 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -148,7 +148,7 @@ test_expect_success 'GIT_PREFIX for built-ins' '
 	(
 		cd dir &&
 		printf "change" >two &&
-		env GIT_EXTERNAL_DIFF=./diff git diff >../actual
+		GIT_EXTERNAL_DIFF=./diff git diff >../actual
 		git checkout -- two
 	) &&
 	test_cmp expect actual
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 3119c8c..1ecdacb 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -409,7 +409,7 @@ test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
 	(echo "From Example <from@example.com>"
 	 echo "To Example <to@example.com>"
 	 echo ""
-	) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
+	) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$patches 2>errors &&
 	! grep "^In-Reply-To: < *>" msgtxt1


	
Junio C Hamano· Mar 7, 2014, 01:14 UTC · re: Junio C Hamano · lore

[micro] Use 'env' on test_must_fail as appropriate

Because "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
	) &&
        ...
which could be expressed as
	... &&
        test_must_fail env VAR=VAL git comand &&
	...
Find and shorten such constructs in existing test scripts.

Note that I am not 100% convinced myself that it is a good idea to do this, so please do not add this to the list without seeing it discussed.

Thanks.

← back to recent threads