{"id":11645,"date":"2021-12-08T05:58:06","date_gmt":"2021-12-08T05:58:06","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=11645"},"modified":"2021-12-08T05:58:28","modified_gmt":"2021-12-08T05:58:28","slug":"solved-setlocal-enabledelayedexpansion-script-not-working","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/setlocal-enabledelayedexpansion-script-not-working\/27441.html","title":{"rendered":"Solved SETLOCAL EnableDelayedExpansion Script Not Working"},"content":{"rendered":"<p>I am trying to write a command script with a FOR loop that sets a variable then compares it to a known value. Looking at examples, like the one below, I need to use EnableDelayedExpansion. Simple enough however I do not see it working. Here is a sample script I am running.<\/p>\n<p>SetLocal EnableDelayedExpansion<\/p>\n<p>set var=before<br \/>\nif &#8220;%var%&#8221; == &#8220;before&#8221; (<br \/>\nset var=after;<br \/>\nif !var! == &#8220;after&#8221; @echo if you see me, it worked<br \/>\n)<\/p>\n<p>This gives me the following output &#8211;<br \/>\nC:\\&gt;test.cmd<br \/>\nC:\\&gt;SetLocal EnableDelayedExpansion<br \/>\nC:\\&gt;set var=before<\/p>\n<p>C:\\&gt;if &#8220;before&#8221; == &#8220;before&#8221; (<br \/>\nset var=after;<br \/>\nif !var! == &#8220;after&#8221;<br \/>\n)<\/p>\n<p>C:\\&gt;<\/p>\n<p>What am I doing wrong here?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":15},"question-category":[55],"question_tags":[],"class_list":["post-11645","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/11645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=11645"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=11645"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=11645"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=11645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}