[{"data":1,"prerenderedAt":159},["ShallowReactive",2],{"post:inline-conditionals":3},{"id":4,"title":5,"body":6,"date":147,"description":148,"draft":149,"extension":150,"meta":151,"navigation":152,"path":153,"seo":154,"stem":155,"tags":156,"__hash__":158},"posts\u002Fposts\u002Finline-conditionals.md","TIL: TIL: Bash Syntax for Inline Conditionals",{"type":7,"value":8,"toc":144},"minimark",[9,24,27,59,70,80,90,93,130,140],[10,11,12,13,18,19,23],"p",{},"Despite the last 15+ years running Ubuntu as my daily driver, I don't spend much time scripting in Bash. Yesterday while working on a ",[14,15,17],"a",{"href":16},"\u002Fposts\u002Fgit-show-file-from-branch\u002F","git release prep skill",", I found myself wondering how to compare version numbers in an inline conditional statement, without resorting to a full ",[20,21,22],"code",{},"if[...];then...fi"," block.",[10,25,26],{},"Well, here it is:",[28,29,34],"pre",{"className":30,"code":31,"language":32,"meta":33,"style":33},"language-bash shiki shiki-themes github-light github-dark","[[ $developmentVersion == $mainVersion ]]; echo $?\n","bash","",[20,35,36],{"__ignoreMap":33},[37,38,41,45,49,52,56],"span",{"class":39,"line":40},"line",1,[37,42,44],{"class":43},"sVt8B","[[ $developmentVersion ",[37,46,48],{"class":47},"szBVR","==",[37,50,51],{"class":43}," $mainVersion ]]; ",[37,53,55],{"class":54},"sj4cs","echo",[37,57,58],{"class":54}," $?\n",[10,60,61,62,65,66,69],{},"In my case, this echoes ",[20,63,64],{},"1"," indicating the two values are not equal. For equal values, a ",[20,67,68],{},"0"," is echoed.",[10,71,72,73,76,77,79],{},"Note that the double-brace syntax (",[20,74,75],{},"[[...]]",") is Bash-specific, as is the double-equals sign (",[20,78,48],{},"), so make sure to use a Bash shebang in your bash scripts:",[28,81,83],{"className":30,"code":82,"language":32,"meta":33,"style":33},"#!\u002Fbin\u002Fbash\n",[20,84,85],{"__ignoreMap":33},[37,86,87],{"class":39,"line":40},[37,88,82],{"class":89},"sJ8bj",[10,91,92],{},"For standard POSIX syntax, we would use:",[28,94,96],{"className":30,"code":95,"language":32,"meta":33,"style":33},"[ \"$developmentVersion\" = \"$mainVersion\" ]; echo $?\n",[20,97,98],{"__ignoreMap":33},[37,99,100,103,107,110,112,115,118,121,123,126,128],{"class":39,"line":40},[37,101,102],{"class":43},"[ ",[37,104,106],{"class":105},"sZZnC","\"",[37,108,109],{"class":43},"$developmentVersion",[37,111,106],{"class":105},[37,113,114],{"class":47}," =",[37,116,117],{"class":105}," \"",[37,119,120],{"class":43},"$mainVersion",[37,122,106],{"class":105},[37,124,125],{"class":43}," ]; ",[37,127,55],{"class":54},[37,129,58],{"class":54},[10,131,132,133,139],{},"And ",[14,134,138],{"href":135,"rel":136},"https:\u002F\u002Fstackoverflow.com\u002Fa\u002F40431336",[137],"nofollow","here's the source for ya...",".",[141,142,143],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}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);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":33,"searchDepth":145,"depth":145,"links":146},2,[],"2026-09-24T09:36:59-04:00","Despite the last 15+ years running Ubuntu as my daily driver, I don't spend much time scripting in Bash. Yesterday while working on a git release prep skill, I found myself wondering how to compare version numbers in an inline conditional statement, without resorting to a full if[...];then...fi block.",false,"md",{},true,"\u002Fposts\u002Finline-conditionals",{"title":5,"description":148},"posts\u002Finline-conditionals",[32,157],"til","VOQjVMxttaTUDEIlPdhY5L0g0uBbTwn-PHbshOpZED8",1793891606388]