
{"id":19033,"date":"2022-07-29T23:50:48","date_gmt":"2022-07-29T18:20:48","guid":{"rendered":"https:\/\/beautifulworknew.wordpress.com\/?p=19033"},"modified":"2022-07-29T23:50:48","modified_gmt":"2022-07-29T18:20:48","slug":"fetching-values-of-environment-variables","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2022\/07\/29\/fetching-values-of-environment-variables\/","title":{"rendered":"Fetching values of  environment variables"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ls\nascii-table     avg.txt               case-changer.c  exist.sh          mph-to-kph.c\nascii-table.c   avg-with-garbage.txt  env-var.c       functions_ver1.c  mph-to-kph_v2.c\nascii-table.md  case-changer          env-var-set.c   functions_ver2.c  output.c\n$cat env-var.c \n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n\nint main(void)\n{\n   \/* Using getenv() to fetch env. variables *\/\n   printf(\"Your username is %s\\n\", getenv(\"USER\"));\n   printf(\"Your home directory is %s\\n\", \n      getenv(\"HOME\"));\n   printf(\"Your preferred editor is %s\\n\", \n      getenv(\"EDITOR\"));\n   printf(\"Your shell is %s\\n\", getenv(\"SHELL\"));\n\n   \/* Check if the current terminal support colors*\/\n   if ( strstr(getenv(\"TERM\"), \"256color\")  )\n   {\n      \/* Color the output with \\033 + colorcode *\/\n      printf(\"\\033[0;31mYour \\033[0;32mterminal \"\n         \"\\033[0;35msupport \"\n         \"\\033[0;33mcolors\\033[0m\\n\");\n   }\n   else\n   {\n      printf(\"Your terminal doesn't support\" \n         \" colors\\n\");\n   }\n   return 0;\n}\n$gcc env-var.c -o env-var.c \ngcc: fatal error: input file \u2018env-var.c\u2019 is the same as output file\ncompilation terminated.\n$gcc env-var.c -o env-var\n$.\/env-var \nYour username is jeffrin\nYour home directory is \/home\/jeffrin\nYour preferred editor is (null)\nYour shell is \/bin\/bash\nYour terminal support colors\n$\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$ls ascii-table avg.txt case-changer.c exist.sh mph-to-kph.c ascii-table.c avg-with-garbage.txt env-var.c functions_ver1.c mph-to-kph_v2.c ascii-table.md case-changer env-var-set.c functions_ver2.c output.c $cat env-var.c #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int main(void) { \/* Using getenv() to fetch env. variables *\/ printf(&#8220;Your username is %s\\n&#8221;, getenv(&#8220;USER&#8221;)); printf(&#8220;Your home directory is %s\\n&#8221;, getenv(&#8220;HOME&#8221;)); printf(&#8220;Your preferred editor is %s\\n&#8221;, getenv(&#8220;EDITOR&#8221;)); printf(&#8220;Your shell is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2022\/07\/29\/fetching-values-of-environment-variables\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fetching values of  environment variables&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19033"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=19033"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19033\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=19033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=19033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=19033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}