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 comment

Your email address will not be published. Required fields are marked *