{"id":1826,"date":"2008-11-12T23:57:05","date_gmt":"2008-11-12T23:57:05","guid":{"rendered":"http:\/\/dev001.dl\/yan\/wdp\/?p=26"},"modified":"2026-01-20T06:03:52","modified_gmt":"2026-01-20T06:03:52","slug":"bash-if","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=1826","title":{"rendered":"bash  &#8212; if"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nif &#91; -n \"$1\" ];then\n    filename = $1;\nelse\n    filename = <span style=\"background-color: initial; font-family: inherit; font-size: inherit; text-align: initial;\">date --date=<\/span>'1 hour ago'\" + %Y-%m-%d.%H\"`;\nfi<\/code><\/pre>\n\n\n<p><strong>Compare numbers with -gt -lt -ne -eq<\/strong><\/p>\n<div style=\"background-color: #ffffe0;\">if [ &#8220;${size}&#8221; -gt 100 ];then<br \/>\u00a0\u00a0echo $size<br \/>fi<\/div>\n<p><strong>Compare strings with = !=<\/strong><\/p>\n<div style=\"background-color: #ffffe0;\">if [ &#8220;${domain}&#8221; = &#8220;lalife.net&#8221; ];then<br \/>echo &#8220;correct&#8221;<br \/>fi<br \/>(#if [ &#8220;${domain}&#8221;=&#8221;lalife.net&#8221; ];then (##this won&#8217;t work without space around &#8220;=&#8221; or &#8220;!=&#8221;)\n<p>When using [[ ]]<br \/>if [[ ${domain} = &#8220;lalife.net&#8221; ]];then<br \/>echo &#8220;correct&#8221;<br \/>fi<\/p>\n<p>([ ] needs the variable to be inside of &#8220;&#8221;)<\/p>\n<p>Match<br \/>if [[ ${domain} =~ &#8220;lalife.net&#8221; ]];then<br \/>echo &#8220;correct&#8221;<br \/>fi<br \/>([ ] doesn&#8217;t work with =~)<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Compare numbers with -gt -lt -ne -eq if [ &#8220;${size}&#8221; -gt 100 ];then\u00a0\u00a0echo $sizefi Compare strings with = != if [ &#8220;${domain}&#8221; = &#8220;lalife.net&#8221; ];thenecho &#8220;correct&#8221;fi(#if [ &#8220;${domain}&#8221;=&#8221;lalife.net&#8221; ];then (##this won&#8217;t work without space around &#8220;=&#8221; or &#8220;!=&#8221;) When using &hellip; <a href=\"http:\/\/www.lalife.net\/?p=1826\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[37],"class_list":["post-1826","post","type-post","status-publish","format-standard","hentry","category-shell","tag-bash"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/1826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1826"}],"version-history":[{"count":5,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/1826\/revisions"}],"predecessor-version":[{"id":1979,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/1826\/revisions\/1979"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1826"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}