{"id":1889,"date":"2008-03-26T18:52:17","date_gmt":"2008-03-26T18:52:17","guid":{"rendered":"http:\/\/scienceblogs.com\/gregladen\/2008\/03\/26\/learning-the-bash-shell-third\/"},"modified":"2008-03-26T18:52:17","modified_gmt":"2008-03-26T18:52:17","slug":"learning-the-bash-shell-third","status":"publish","type":"post","link":"https:\/\/gregladen.com\/blog\/2008\/03\/26\/learning-the-bash-shell-third\/","title":{"rendered":"Learning the bash shell, third look"},"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\" \/>Time for another installment of our look at the book <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>.  Today&#8217;s foray into Linux Land:  Unix Command Substitution.<!--more-->There is more than one way to do this, but here is a sensible way to look at the format.  In command substitution you stick something that comes out to be a valid UNIX command insice parentheses preceded with a dollar sign:$(UNIX command)The unix command is evaluated and then the result replaces the $() bit.For example, say you wanted to edit all of the files in the current directory that included the letters &#8220;html&#8221;.  You could use the &#8220;grep&#8221; command to parse out all of the files to get a look at them.  Grep goes through files and searches for a string, and by default spits out the line containing the string.  There is an option (-l) that tells grep to spit out only the filename. So, for instance, I can do this:<code>greg@greg-desktop:~\/Desktop$ cd markdowngreg@greg-desktop:~\/Desktop\/markdown$ grep -l 'html' *4sh.htmlblog2.htmlblog2.txtblogrolJava.txtblogroll_master_SUboneyard.htmlboneyard.txtcalendar2htmldebate2.html...<\/code>Then I could type these names into the text editor command.Or, I can turn this list of phrases into part of a command line.  If I use &#8220;getdit&#8221; as the text editor, I can type&#8221;<code>gedit grep -l 'html' *<\/code>But that would not work! -l is not an available option for gedit, and there are other confusing things on this line to cause gedit to not get it.  Get it? Good.BUt, if I put the mojo that spits out the list of files (which I tried above and know works) into the command sbustitution command, then then that will convert &#8220;grep -l &#8216;html&#8217; *&#8221; into a a list of files.So this works:<codce>greg@greg-desktop:~\/Desktop\/markdown$ gedit $(grep -l html *) &#038;<\/code>This is the same as typing:greg@greg-desktop:~\/Desktop\/markdown$ gedit 4sh.html blog2.html blog2.txt &#8230;. and so on.  The &#8220;and&#8221; sign at the end puts the operation into the background so I can keep using the same command line.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time for another installment of our look at the book Learning the bash Shell (In a Nutshell (O&#8217;Reilly)). Today&#8217;s foray into Linux Land: Unix Command Substitution.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"1","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[164,67,130,57],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5fhV1-ut","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/1889"}],"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=1889"}],"version-history":[{"count":0,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/1889\/revisions"}],"wp:attachment":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/media?parent=1889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/categories?post=1889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/tags?post=1889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}