Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:56

Jeff King [off-list ref] writes:
quoted
without requiring the brain-cycle to waste on the "Is this simple enough
for even Solaris to grok?" guess game.  This should also be reusable for
other stuff like $PERL_PATH, I would think.
I like it. Even better would be:

  write_script() {
        echo "#!$2" >"$1" &&
        cat >>"$1" &&
        chmod +x "$1"
  }

  write_script foo.sh "$SHELL_PATH" <<-\EOF
    echo my arguments are "$@"
  EOF
I first thought that the order of parameters were unusual, but with that
order, you could even go something fancier like:

	write_script () {
		case "$#" in
		1)	case "$1" in
			*.perl | *.pl) echo "#!$PERL_PATH" ;;
			*) echo "#!$SHELL_PATH" ;;
			esac
                2)	echo "#!$2" ;;
		*)	BUG ;;
                esac >"$1" &&
                cat >>"$1" &&
                chmod +x "$1"
	}

	write_script foo.sh
        write_script bar.perl
        write_script pre-receive /no/frobnication/today

The tongue-in-cheek comment aside, I think ${2-"$SHELL_PATH"} or some form
of fallback would be a good idea in any case, as 99% of the time what we
write in the test scripts is a shell script.

Also "chmod +x" is a very good idea.

        

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Jeff King <hidden>
Date: 2016-06-15 22:52:56

On Fri, Feb 03, 2012 at 01:50:33PM -0800, Junio C Hamano wrote:
quoted
  write_script foo.sh "$SHELL_PATH" <<-\EOF
    echo my arguments are "$@"
  EOF
I first thought that the order of parameters were unusual, but with that
order, you could even go something fancier like:

	write_script () {
		case "$#" in
		1)	case "$1" in
			*.perl | *.pl) echo "#!$PERL_PATH" ;;
			*) echo "#!$SHELL_PATH" ;;
			esac
                2)	echo "#!$2" ;;
		*)	BUG ;;
                esac >"$1" &&
                cat >>"$1" &&
                chmod +x "$1"
	}
Nice. I was going to suggest a wrapper like "write_sh_script" so you
didn't have to spell out $SHELL_PATH, but I think the auto-detection
makes sense (and falling back to shell makes even more sense, as that
covers 99% of the cases anyway).

-Peff

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Ben Walton <hidden>
Date: 2016-06-15 22:52:56

Excerpts from Jeff King's message of Fri Feb 03 16:55:07 -0500 2012:
quoted
    write_script () {
        case "$#" in
        1)    case "$1" in
            *.perl | *.pl) echo "#!$PERL_PATH" ;;
            *) echo "#!$SHELL_PATH" ;;
            esac
                2)    echo "#!$2" ;;
        *)    BUG ;;
                esac >"$1" &&
                cat >>"$1" &&
                chmod +x "$1"
    }
Nice. I was going to suggest a wrapper like "write_sh_script" so you
didn't have to spell out $SHELL_PATH, but I think the auto-detection
makes sense (and falling back to shell makes even more sense, as that
covers 99% of the cases anyway).
This looks like a very nice, general purpose, solution to the problem.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help