Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

zsh: "export: not valid in this context"

4,880 views
Skip to first unread message

kj

unread,
Nov 29, 2010, 5:26:34 PM11/29/10
to

I want the value of my environment variable GIT_PAGER to be set to
the string produced by =less followed by the string "${LESS}r",
where $LESS is a previously set variable. In my current system,
the whole thing should amount to the string "/usr/bin/less -XFmij4r".

I can't figure out how to do this. First, I don't know how to
interpolate =less directly into a string. (Can it be done?) So
I tried this ugly hack:

export GIT_PAGER=$(printf "%s %sr" =less $LESS)

...but I get the error

export: not valid in this context: -XFmij4r

How can I do this easily?

This question is motivated only by a desire to better understand
zsh (how to interpolate =cmd constructs, and how to understand the
export error above), rather than about how to solve this particular
problem, since I know that I can achieve the desired result by
first setting GIT_PAGER, and then exporting it.

TIA!

~kj

Alan Curry

unread,
Nov 29, 2010, 6:35:22 PM11/29/10
to
In article <id19aq$ku9$1...@reader1.panix.com>, kj <no.e...@please.post> wrote:
>
>export GIT_PAGER=$(printf "%s %sr" =less $LESS)

The result of $() is subject to word splitting, resulting in this:

export GIT_PAGER=/usr/bin/less -XFmij4r

where you meant to have:

export GIT_PAGER="/usr/bin/less -XFmij4r"

So you're effectively trying to export 2 variables, one of which has a name
starting with a dash, and the shell refuses to do it.

Add some quotes, and it'll work:

export GIT_PAGER="$(printf "%s %sr" =less $LESS)"

The use of the =cmd construct didn't have anything to do with it.

--
Alan Curry

kj

unread,
Nov 29, 2010, 10:16:18 PM11/29/10
to
In <id1dbq$bho$1...@speranza.aioe.org> pac...@kosh.dhis.org (Alan Curry) writes:

>In article <id19aq$ku9$1...@reader1.panix.com>, kj <no.e...@please.post> wrote:
>>
>>export GIT_PAGER=$(printf "%s %sr" =less $LESS)

>The result of $() is subject to word splitting, resulting in this:

> export GIT_PAGER=/usr/bin/less -XFmij4r

>where you meant to have:

> export GIT_PAGER="/usr/bin/less -XFmij4r"

>So you're effectively trying to export 2 variables, one of which has a name
>starting with a dash, and the shell refuses to do it.

Ah, I get it. Thanks!

~kj

Kinsley Deng

unread,
Nov 30, 2010, 8:33:00 PM11/30/10
to
I don't know why you're not able to do it with printf,in my UBUNTU,it's OK.
Kins.

0 new messages