{"id":232,"date":"2012-12-01T13:22:03","date_gmt":"2012-12-01T13:22:03","guid":{"rendered":"http:\/\/www.timokorthals.de\/?p=232"},"modified":"2016-12-28T00:20:52","modified_gmt":"2016-12-27T23:20:52","slug":"running-cd-from-a-shell","status":"publish","type":"post","link":"http:\/\/www.timokorthals.de\/?p=232","title":{"rendered":"Running &#8216;cd&#8217; &#038;&#038; &#8216;ls&#8217; from a shell"},"content":{"rendered":"<p>I wanted to write a script, so that I can change the directory and list the content with only one command. Like  <span class=\"lang:sh decode:true  crayon-inline \" >cd ~\/Downloads; ls -la<\/span> <\/p>\n<p>so I wrote the following script called <strong>cdl<\/strong>, and copied it to <strong>\/usr\/local\/bin<\/strong> to make it accessable from everywhere:<\/p>\n<pre class=\"lang:sh decode:true \" >#!\/bin\/sh\r\nif [ $# -ne 1 ]\r\nthen\r\n  echo \"Usage: cdl [Directory]\"\r\nelse\r\n  cd $1\r\n  ls -la\r\nfi<\/pre>\n<p><span style=\"color: #ff0000;\"><span style=\"color: #000000;\">The problem is here, that when I run the script, the commands in the script wont be run in the active shell. To do so, it has to be run with the dotsource, like <strong>. cdl ~\/Downloads<\/strong>, \u00a0but this suxxs. To run the script without the dotsource, there needs to be an alias in the <strong>~\/.bashrc<\/strong>:<\/span><\/span><\/p>\n<pre class=\"lang:sh decode:true \" >alias cdl='. cdl'<\/pre>\n<p>Now I can access an folder and list the content with <strong>cdl ~\/Downloads<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to write a script, so that I can change the directory and list the content with only one command. Like cd ~\/Downloads; ls -la so I wrote the following script called cdl, and copied it to \/usr\/local\/bin to make it accessable from everywhere: #!\/bin\/sh if [ $# -ne 1 ] then echo &#8220;Usage: &hellip; <a href=\"http:\/\/www.timokorthals.de\/?p=232\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Running &#8216;cd&#8217; &#038;&#038; &#8216;ls&#8217; from a shell<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/posts\/232"}],"collection":[{"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":2,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":408,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions\/408"}],"wp:attachment":[{"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.timokorthals.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}