help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] echo and environment variables


From: Christof Warlich
Subject: [Help-bash] echo and environment variables
Date: Thu, 5 Oct 2017 19:22:34 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]