{"id":9363,"date":"2014-08-23T22:07:40","date_gmt":"2014-08-24T02:07:40","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=9363"},"modified":"2014-08-23T22:07:40","modified_gmt":"2014-08-24T02:07:40","slug":"better-bash-scripting","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/08\/23\/better-bash-scripting\/","title":{"rendered":"Better Bash Scripting"},"content":{"rendered":"<p><a href=\"http:\/\/robertmuth.blogspot.com\/2012\/08\/better-bash-scripting-in-15-minutes.html\">Robert Muth<\/a>:<\/p>\n<blockquote cite=\"http:\/\/robertmuth.blogspot.com\/2012\/08\/better-bash-scripting-in-15-minutes.html\">\n<p>I start every bash script with the following prolog:<\/p>\n<pre>#!\/bin\/bash\nset -o nounset\nset -o errexit<\/pre>\n<p>This will take care of two very common errors:<\/p>\n<ol><li>Referencing undefined variables (which default to &ldquo;&rdquo;) <\/li>\n<li>Ignoring failing commands<\/li><\/ol>\n<p>[&#8230;]<\/p>\n<p>Bash has a number of (underappreciated) ways to manipulate strings.<\/p>\n<p>[&#8230;]<\/p>\n<p>Some commands expect filenames as parameters  so straightforward pipelining does not work.\nThis is where <code>&lt;()<\/code> operator comes in handy as it takes a command and transforms it into something which can be used as a filename.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Robert Muth: I start every bash script with the following prolog: #!\/bin\/bash set -o nounset set -o errexit This will take care of two very common errors: Referencing undefined variables (which default to &ldquo;&rdquo;) Ignoring failing commands [&#8230;] Bash has a number of (underappreciated) ways to manipulate strings. [&#8230;] Some commands expect filenames as parameters [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[767,71],"class_list":["post-9363","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bash","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=9363"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9363\/revisions"}],"predecessor-version":[{"id":9364,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9363\/revisions\/9364"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=9363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=9363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=9363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}