Saturday, January 2, 2016

Re: (inconsistent?) behavior of environment variables

Tim Chase wrote:

> Tripped over the following on Linux & BSD:
>
> bash$ echo $USER
> tim
> bash$ echo $UID
> 1000
> bash$ vim
> :echo $USER
> tim
> :echo $UID
> :echo expand('$UID')
> 1000
>
> Note that the ":echo $UID" didn't actually return anything. Yet
> running it through expand() produced the expected result. I
> confirmed the behavior to make sure that it wasn't some redraw issue,
> using the expression register in insert-mode, inserting =$UID and
> =expand('$UID') and got the same mismatched behavior.
>
> Based on the description of "expr9" at ":help expression-syntax",
> "$VAR" should contain that environment variable's content.
>
> Is there something I'm missing here or reasoning for the difference?
> Or documentation that I missed?

I believe $UID is a shell variable (bash only?) which is not exported.
Thus Vim doesn't get it. When using expand() the shell is used to
expand the variable, thus then you do get it.

--
TIM: To the north there lies a cave, the cave of Caerbannog, wherein, carved
in mystic runes, upon the very living rock, the last words of Olfin
Bedwere of Rheged make plain the last resting place of the most Holy
Grail.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: