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
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
>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