{"id":321,"date":"2025-06-21T14:59:50","date_gmt":"2025-06-21T14:59:50","guid":{"rendered":"https:\/\/pipeawk.com\/?p=321"},"modified":"2025-06-21T14:59:50","modified_gmt":"2025-06-21T14:59:50","slug":"the-path-variable-explained","status":"publish","type":"post","link":"https:\/\/pipeawk.com\/index.php\/2025\/06\/21\/the-path-variable-explained\/","title":{"rendered":"The PATH Variable Explained"},"content":{"rendered":"<p>In most computer systems, there is a variable which defines the order in which, your programs, when executed, are located on the file system.<\/p>\r\n<p>In this post, I will attempt to explain the PATH variable, which is the variable that defines the location, the operating system shell, searches for the executable programs.<!--more--><\/p>\r\n<p>When you open a shell in Linux for example, you are presented with something similar to the infamous &#8220;<strong>$<\/strong>&#8221; prompt for regular users or the pound &#8220;<strong>#<\/strong>&#8221; prompt for administrative\/root users. The prompt is simply waiting for you input to execute it. Now, let&#8217;s give the prompt a command and see the response, we will then break the actions a part and understand how the PATH variable is involved with the action.<\/p>\r\n<p>Now, let&#8217;s type the following command followed by the &#8216;Enter&#8217; key:<\/p>\r\n<blockquote>\r\n<p><strong>echo &#8220;Hello!&#8221;<\/strong><\/p>\r\n<\/blockquote>\r\n<p>You should get the following output:<\/p>\r\n<blockquote>\r\n<p><strong>Hello!<\/strong><\/p>\r\n<\/blockquote>\r\n<p>The command\u00a0<strong>echo\u00a0<\/strong>simply tells the shell to get the quoted string and print it. But in reality, the command echo is a separate executable located somewhere in the filesystem. Now let&#8217;s type the following command to identify where the command is located on the file system:<\/p>\r\n<blockquote>\r\n<p><strong>which echo<\/strong><\/p>\r\n<\/blockquote>\r\n<p>you should get the following output, at least on most systems, the location might vary:<\/p>\r\n<blockquote>\r\n<p><strong>\/usr\/bin\/echo<\/strong><\/p>\r\n<\/blockquote>\r\n<p><strong>\/usr\/bin\/echo<\/strong> is the actual location where the executable\u00a0<strong>echo<\/strong> is located. But now, you should ask yourself a question; how did the system knew where the location of echo was? The answer is: the\u00a0<strong>PATH<\/strong> variable.<\/p>\r\n<p>Now, type the following command and press the &#8216;Enter&#8217; key:<\/p>\r\n<blockquote>\r\n<p><strong>echo $PATH<\/strong><\/p>\r\n<\/blockquote>\r\n<p>You should get an output similar to the following:<\/p>\r\n<blockquote>\r\n<p><strong>\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games:\/usr\/local\/games:\/snap\/bin<\/strong><\/p>\r\n<\/blockquote>\r\n<p>The content of the PATH variable is a string containing a list of directories separated by the &#8220;:&#8221; character, containing all\u00a0 the directories\/folders the shell will search for when you enter a command. When you entered <strong>echo &#8220;Hello!&#8221;<\/strong>, the system starts scanning the PATH variables until the\u00a0<strong>echo\u00a0<\/strong>executable is found, in this case, the following search order is scanned:<\/p>\r\n<ul>\r\n<li>does the directory\u00a0<strong>\/usr\/local\/sbin<\/strong> contain the\u00a0<strong>echo<\/strong> executable? No<\/li>\r\n<li>does the directory <strong>\/usr\/local\/bin\u00a0<\/strong>contain the\u00a0<strong>echo\u00a0<\/strong>executable? No<\/li>\r\n<li>does the directory <strong>\/usr\/sbin <\/strong>contain the\u00a0<strong>echo\u00a0<\/strong>executable? No<\/li>\r\n<li>does the directory <strong>\/usr\/bin <\/strong>contain the\u00a0<strong>echo\u00a0<\/strong>executable?\u00a0<strong>YES<\/strong><\/li>\r\n<\/ul>\r\n<p>At this point, the search ends, and <strong>\/usr\/bin\/echo &#8220;Hello!&#8221;<\/strong> command is executed behind the scenes, and the output\u00a0<strong>Hello! <\/strong>is displayed.<\/p>\r\n<p>There are many more things that happen when a program is executed, but for the simplicity of this post, we will end here.<\/p>\r\n<p>On Windows there is also a PATH variable, the only difference is the separation character, on Windows the character &#8220;<strong>;<\/strong>&#8221; is used instead.<\/p>\r\n<p>I hope now you have a better idea of what the PATH variable is and how it&#8217;s used.<\/p>\r\n<p>Thank you for reading this post, and I hope it makes a difference in your UNIX understanding journey. Happy typing&#8230;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>In most computer systems, there is a variable which defines the order in which, your programs, when executed, are located on the file system. In this post, I will attempt to explain the PATH variable, which is the variable that defines the location, the operating system shell, searches for the executable programs.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-unix"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/comments?post=321"}],"version-history":[{"count":13,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/media?parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/categories?post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/tags?post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}