On Wed, 04 Oct 2023 10:15:30 -0700 Junio C. Hamano wrote: > Štěpán Němec <stepnem@xxxxxxxx> writes: > >> Yes, this is even simpler and more obvious, although for some reason, >> the subshell version works just as well, i.e., with just >> TEST_DIRECTORY=$(cd . && pwd) (no cd in the parent) in test-lib.sh and >> >> cat <<EOF >./tslash.sh >> #!/bin/sh >> test_description='yada yada' >> >> . ./test-lib.sh >> >> test_expect_success 'check TEST_DIRECTORY for trailing slash' ' >> echo "$TEST_DIRECTORY" && >> test "$TEST_DIRECTORY" = "${TEST_DIRECTORY%/}" >> ' >> >> test_done >> EOF > > If the only thing you checked was if TEST_DIRECTORY has or does not > have a trailing slash, then it is totally understandable how and why > the chdir inside subshell works. The value $(pwd) in the subshell > returns, that is assigned to TEST_DIRECTORY, is canonicalized. But > the outer shell still thinks $(pwd) is with trailing slash, and the > above does not test it. Oh my, of course... thanks. > > test_expect_success 'check $PWD for trailing slash' ' > echo "$PWD" && > test "$PWD" = "${PWD%/}" > ' > The primary reason why I said I was silly doing it in a subshell was > because I wanted to make sure that any test that refers to $PWD or > $(pwd) later in the code would not get upset the same way with > trailing slash after $PWD or $(pwd). The $PWD inside the test is the trash directory, though, so that's not the problematic $PWD with a trailing slash any more, so I guess this problem can't really happen in a test that follows the '. ./test-lib.sh' (which does cd -P "$TRASH_DIRECTORY") convention? -- Štěpán