[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] echo and environment variables
From: |
Nick Chambers |
Subject: |
Re: [Help-bash] echo and environment variables |
Date: |
Thu, 05 Oct 2017 17:28:01 +0000 |
On Thu, Oct 5, 2017 at 12:24 PM Christof Warlich <address@hidden>
wrote:
> Hi,
>
> I'm a bit surprised: Can anyone tell why
>
> $ xxx=hiho echo $xxx # xxx is only set for the current command
>
> prints an empty line, while
>
> $ xxx=hiho; echo $xxx; unset xxx # please note the semicolon!
>
> prints
>
> hiho
>
> as expected?
>
> Furthermore, note that these few lines of C code:
>
> #include <stdio.h>
> #include <stdlib.h>
> int main () {
> char *xxx = getenv ("xxx");
> if(xxx != NULL) printf("%s\n", xxx);
> return 0;
> }
>
> _do_ print
>
> hiho
>
> when called either way, i.e like this.:
>
> $ xxx=hiho ./a.out
> hiho
>
> and like this:
>
> xxx=hiho; ./a.out; unset xxx
> hiho
>
> Thanks for any ideas,
>
> Chris
http://mywiki.wooledge.org/BashFAQ?action=show&redirect=BashFaq#BashFAQ.2F104.Why_doesn.27t_foo.3Dbar_echo_.22.24foo.22_print_bar.3F
>
>
>
>
>
>