Setting value to an environment variable


$ls
ascii-table     avg.txt               case-changer.c  env-var-set.c     functions_ver2.c  output.c
ascii-table.c   avg-with-garbage.txt  env-var         exist.sh          mph-to-kph.c
ascii-table.md  case-changer          env-var.c       functions_ver1.c  mph-to-kph_v2.c
$cat env-var-set.c 
#define _POSIX_C_SOURCE 200112L
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    setenv("FULLNAME", "Jack-Benny", 1);
    printf("Your full name is %s\n", getenv("FULLNAME"));
    return 0;
}
$gcc env-var-set.c -o env-var-set

$
$./env-var-set 
Your full name is Jack-Benny
$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: