{"id":118,"date":"2013-08-21T23:49:00","date_gmt":"2013-08-21T23:49:00","guid":{"rendered":"https:\/\/moondog.org\/setting-a-default-if-an-argument-isnt-passed\/"},"modified":"2020-04-04T13:51:21","modified_gmt":"2020-04-04T20:51:21","slug":"setting-a-default-if-an-argument-isnt-passed","status":"publish","type":"post","link":"https:\/\/moondog.org\/?p=118","title":{"rendered":"Setting a default if an argument isn&#8217;t passed"},"content":{"rendered":"<p>In doing some bash scripting&#8230; I use some simple scripts to automate commands so I don&#8217;t have to type in (or remember) all the parameters. This script uses the du command to show me the disk usage on directories. The depth parameter specifies how deep in the path to go when reporting. I wanted the script to function correctly without an argument. So my solution was to test for the argument and use a default value if it&#8217;s not present. Without a default value, this command would produce an error.<\/p>\n<blockquote><p><span style=\"font-family: Courier New, Courier, monospace; font-size: small;\"><span style=\"background-color: #cfe2f3;\"><span style=\"background-color: #666666;\"><span style=\"color: #eeeeee;\">#!\/bin\/bash<br \/>depth=&#8221;$1&#8243;<br \/># If depth is not specified, default to zero<br \/>if [[ $depth = &#8220;&#8221; ]]; then<br \/>depth=&#8221;0&#8243;<br \/>fi<br \/>du -mc -d$depth &#8211;apparent-size * | sort -nr | less<\/span><\/span><\/span><\/span><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>In doing some bash scripting&#8230; I use some simple scripts to automate commands so I don&#8217;t have to type in (or remember) all the parameters. This script uses the du command to show me the disk usage on directories. The depth parameter specifies how deep in the path to go when reporting. I wanted the &hellip; <a href=\"https:\/\/moondog.org\/?p=118\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting a default if an argument isn&#8217;t passed&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-technology"],"_links":{"self":[{"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moondog.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=118"}],"version-history":[{"count":1,"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/moondog.org\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/moondog.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moondog.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moondog.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}