Re: [PATCH] t4014: shell portability fix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 31, 2016 at 11:44:13PM -0400, Jeff King wrote:

> # probably not portable; also, possible without sub-program?
> is_exported () {
> 	export -p | grep "^declare -x $1="
> }

Obviously this should have been "grep -q" (and my test didn't notice
because the variable isn't actually exported!).

But yeah, this is not very portable. Doing:

  export AAAA=content
  for i in bash dash mksh ksh93
  do
    printf '%5s ==> ' $i
    $i -c 'export -p' | head -1
  done

yields:

   bash ==> declare -x AAAA="content"
   dash ==> export AAAA='content'
   mksh ==> export AAAA=content
  ksh93 ==> export AAAA=content

which is actually not too hard to pattern-match, but who knows what else
exists. I guess another strategy would be to actually spawn a
sub-process and see if it has the variable set.

I think my code also doesn't handle exported-but-unset variables, though
I'm not sure we really need to care about that in practice.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]