I am attempting to familiarize myself with BASH so i can work in a Unix environment. I want to export a shell variable to a simple C program but seem to be unable to do so.

Here is the C program: (i am also very unfamiliar with C but this came from a tutorial so i don't think it is is incorrect)

#include <stdio.h>
#include <stdlib.h>

int main(void) {
  char *myenvvar=getenv("EDITOR");
  printf("The editor environment variable is set to %s\n",myenvvar);
}

i compile it and have the executable all set and ready, and then in BASH i was thinking something as simple as "> export $EDITOR='emacs' \n" should work and export the shell variable to someplace my C program can access it.

Am i making some stupid mistake? (i hope i am) or do i have this totally wrong?

Thanks

The $ sigil is only used when referencing a variable that's already defined -- in an export command it should be omitted, as in export EDITOR=vim .

Thank you very much, that resolved the issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.