{"id":1528,"date":"2008-02-23T13:01:02","date_gmt":"2008-02-23T13:01:02","guid":{"rendered":"http:\/\/scienceblogs.com\/gregladen\/2008\/02\/23\/learning-the-bash-shell\/"},"modified":"2008-02-23T13:01:02","modified_gmt":"2008-02-23T13:01:02","slug":"learning-the-bash-shell","status":"publish","type":"post","link":"https:\/\/gregladen.com\/blog\/2008\/02\/23\/learning-the-bash-shell\/","title":{"rendered":"Learning the Bash Shell"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/scienceblogs.com\/gregladen\/wp-content\/blogs.dir\/472\/files\/2012\/04\/i-30a1e0366512a8ac50ae2cf969f02d73-learning_bash_shell.jpg?w=604\" alt=\"i-30a1e0366512a8ac50ae2cf969f02d73-learning_bash_shell.jpg\" data-recalc-dims=\"1\" \/>For the most part, computer operating systems all have a &#8220;shell.&#8221;  When people talk about the &#8220;command line&#8221; &#8230; they are talking about the prompt in a shell.  The concept of a shell, and the way we think of a shell today mostly stems from its implementation on Unix systems.  A shell is a computer program that has a human interface and a number of built in or accessible functions (mostly other programs) that humans can invoke to make the computer do something.  On &#8216;servers&#8217; and on most computers back in the old days, the shell would typically appear as a prompt on a computer screen, and that would be all you would get.  You type stuff in, and the computer types stuff as well, and between the two of you, stuff happens.  On a computer with a graphical user interface (GUI), there is still a shell, but it looks different.  The shell is less tangible to the human user, but the GUI itself is a program that provides the user interface, and it may either be the shell itself or it may be invoked automatically as the computer starts up by the shell.<!--more-->Back in Windows 3.X days, the shell was called &#8220;Win&#8221; and there was a file on the computer that said, somewhere, &#8220;Shell=Win&#8221;  or words to that effect.  A neat trick to compensate for the fact that even then Windows was over-demanding of valuable hardware resources (memory and stuff) was to change this line so that it said &#8220;Shell=Word&#8221;  &#8230; this was useful if you only wanted to run Word &#8230;. the windows desktop would not load, and thus not be using up resources.  (Of course, you could run other programs by invoking them from within Word&#8230;.  ah, the old days.)One of the earliest Unix-type shells was called &#8220;sh&#8221; for &#8220;shell.&#8221;  There were various shells, and for a time, shells competed with each other for dominance.  At some point, I&#8217;m not sure how far back (maybe forever) a neat convention was worked into Unix\/Linux systems such that if you invoked a shell different than the one you were using &#8230;  like, if you wanted to run the korn shell and you were in the sh shell &#8230; you would just type the name of the new shell and that would replace, rather than run as a sub process in, the old shell.  That is probably the least important thing you are going to learn today.  Or all week, for that matter.Somewhat more relevant is this question:  What is the &#8220;BASH&#8221; shell?  Well, there was a shell born of sh that was, and still is, called &#8220;Bourne&#8221; after it&#8217;s inventor, Stephen Bourne, in 1978.  (No relation to Jason.) Later, yet another shell was developed based on Bourne, but better.  Born of Bourne through the efforts of Brian Fox in 1987, the new shell was called &#8220;Born Again Shell&#8221;  &#8230; or, for short, BASH. BASH was written as part of the GNU project, and is thus one of the key pieces of software that runs on Linux systems.People will argue about this, but BASH is probably the best shell, the most modern shell, the coolest shell, for use in Linux.  If you are going to learn how to use a shell, this is the shell to learn.  In Ubuntu Linux, if you start a terminal, it will typically be a BASH shell that runs.<a href=\"http:\/\/www.amazon.com\/gp\/product\/0596009658?ie=UTF8&#038;tag=wwwgregladenc-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596009658\">Learning the bash Shell (In a Nutshell (O&#8217;Reilly))<\/a><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=wwwgregladenc-20&#038;l=as2&#038;o=1&#038;a=0596009658\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/> is an excellent, highly recommended introductory volume on BASH.  It is one of a number of books that I would recommend for anyone who wants to learn BASH.  Many parts of this book are too rudementary for many who would have an interst &#8230; chances are if you want to learn bash programming, you probably already know enough to be slighly annoyed at a very introductory book.  However, it also may be true that you have not been systematic and thorough in your coverage of bash.  So, I recommend this book to anyone who cannot answer he following questions:<em>What is a path, where is your path stored, how do you change it on the fly, and how do you change it permanently?How do you take a text file full of shell commands and make it into an executable file that you can run any time you want from the command prompt?What is a &#8216;select&#8217; command and why is it cool?Considerer the following bash program:<\/em><code>filename=$1if [-a $filename]; thenexit 0fi<\/code><em>1) What is wrong with the syntax of the second line?  (Hint:  The programmer has spaced something out)2) What will this program do?3) Why does the third line say &#8220;exit 0&#8221; and not &#8220;exit 1&#8221;?<\/em>If you know the answer to all of these questions, then you probably don&#8217;t need this book.  If you know the answer to none of these questions, then you probably need this book.  If you fall in between, then, well, that&#8217;s a tough decision.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the most part, computer operating systems all have a &#8220;shell.&#8221; When people talk about the &#8220;command line&#8221; &#8230; they are talking about the prompt in a shell. The concept of a shell, and the way we think of a shell today mostly stems from its implementation on Unix systems. A shell is a computer &hellip; <a href=\"https:\/\/gregladen.com\/blog\/2008\/02\/23\/learning-the-bash-shell\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Learning the Bash Shell<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"1","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[40,164,67,130,57],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5fhV1-oE","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/1528"}],"collection":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/comments?post=1528"}],"version-history":[{"count":0,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/1528\/revisions"}],"wp:attachment":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/media?parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/categories?post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/tags?post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}