From: Jeff King Date: Wed, 01 Jun 2016 03:54:08 GMT Subject: Re: [PATCH] t4014: shell portability fix Message-ID: <20160601035408.GD5411@sigill.intra.peff.net> In-Reply-To: <20160601034413.GC5411@sigill.intra.peff.net> 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