[{"data":1,"prerenderedAt":162},["ShallowReactive",2],{"post:if-statements-in-bash-scripts":3},{"id":4,"title":5,"body":6,"date":150,"description":151,"draft":152,"extension":153,"meta":154,"navigation":155,"path":156,"seo":157,"stem":158,"tags":159,"__hash__":161},"posts\u002Fposts\u002Fif-statements-in-bash-scripts.md","TIL: If Statements In Bash Scripts",{"type":7,"value":8,"toc":148},"minimark",[9,28,37,89,92,95,128,135,144],[10,11,12,13,24,25,27],"p",{},"Ok, so this is nothing mind-blowing. I may spend a lot of time in bash, but very little of that goes into writing scripts. Well, today I was downloading websites using a ",[14,15,19,23],"a",{"href":16,"rel":17},"https:\u002F\u002Fbitbucket.org\u002Fsnippets\u002FmbornBCG\u002F6eG6kn",[18],"nofollow",[20,21,22],"code",{},"wget"," script I wrote"," specifically for that purpose, and had to add an if statement to construct some conditional ",[20,26,22],{}," arguments.",[10,29,30,31,36],{},"Here's how I thought a bash \u002F shell if statement would work. (I confess, I did have to Google this one, and found a ",[14,32,35],{"href":33,"rel":34},"http:\u002F\u002Fbencane.com\u002F2014\u002F01\u002F27\u002F8-examples-of-bash-if-statements-to-get-you-started\u002F",[18],"great article with examples",".)",[38,39,44],"pre",{"className":40,"code":41,"language":42,"meta":43,"style":43},"language-bash shiki shiki-themes github-light github-dark","if [ $WGET_OPTS -eq 1 ] then\n  \u002F\u002F blabla\nfi\n","bash","",[20,45,46,72,83],{"__ignoreMap":43},[47,48,51,55,59,62,66,69],"span",{"class":49,"line":50},"line",1,[47,52,54],{"class":53},"szBVR","if",[47,56,58],{"class":57},"sVt8B"," [ $WGET_OPTS ",[47,60,61],{"class":53},"-eq",[47,63,65],{"class":64},"sj4cs"," 1",[47,67,68],{"class":57}," ] ",[47,70,71],{"class":53},"then\n",[47,73,75,79],{"class":49,"line":74},2,[47,76,78],{"class":77},"sScJk","  \u002F\u002F",[47,80,82],{"class":81},"sZZnC"," blabla\n",[47,84,86],{"class":49,"line":85},3,[47,87,88],{"class":53},"fi\n",[10,90,91],{},"This threw an error!",[10,93,94],{},"Here is the correct syntax:",[38,96,98],{"className":40,"code":97,"language":42,"meta":43,"style":43},"if [ $WGET_OPTS -eq 1 ]\nthen\n  \u002F\u002F blabla\nfi\n",[20,99,100,113,117,123],{"__ignoreMap":43},[47,101,102,104,106,108,110],{"class":49,"line":50},[47,103,54],{"class":53},[47,105,58],{"class":57},[47,107,61],{"class":53},[47,109,65],{"class":64},[47,111,112],{"class":57}," ]\n",[47,114,115],{"class":49,"line":74},[47,116,71],{"class":53},[47,118,119,121],{"class":49,"line":85},[47,120,78],{"class":77},[47,122,82],{"class":81},[47,124,126],{"class":49,"line":125},4,[47,127,88],{"class":53},[10,129,130,131,134],{},"Today I Learned: If statements in shell scripts require the ",[20,132,133],{},"then"," keyword to be on a separate line.",[10,136,137,138,143],{},"(As a sidenote, this should be considered under the age-old question: ",[14,139,142],{"href":140,"rel":141},"https:\u002F\u002Fsoftwareengineering.stackexchange.com\u002Fquestions\u002F2715\u002Fshould-curly-braces-appear-on-their-own-line",[18],"\"Should curly braces appear on their own line?\"",")",[145,146,147],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":43,"searchDepth":74,"depth":74,"links":149},[],"2018-04-10T09:39:12-04:00","Ok, so this is nothing mind-blowing. I may spend a lot of time in bash, but very little of that goes into writing scripts. Well, today I was downloading websites using a wget script I wrote specifically for that purpose, and had to add an if statement to construct some conditional wget arguments.",false,"md",{},true,"\u002Fposts\u002Fif-statements-in-bash-scripts",{"title":5,"description":151},"posts\u002Fif-statements-in-bash-scripts",[42,160],"til","Iv9JxSEc8o-HOtClwoz6I3zq7yLfPPPPf5p062fMKF4",1790471528307]