-1

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ctpwwner
0

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 .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.