What's the difference between the use of %s and %%s in BAT or CMD or commandline scripts (and as seen on tech solutions on the Net)?

Hello, Everyone, I found two very similar one-liners as part of the solution to WMI issues in SCCM client installation:

1.) from https://www.virtuallyboring.com/microsoft-wmi-invalid-class-error-0x80041010/
dir /b *.mof *.mfl | findstr /v /i uninstall > moflist.txt & for /F %s in (moflist.txt) do mofcomp %s

2.) from https://blogs.technet.microsoft.com/yongrhee/2016/06/23/wmi-stop-hurting-yourself-by-using-for-f-s-in-dir-s-b-mof-mfl-do-mofcomp-s/
dir /b *.mof *.mfl | findstr /v /i uninstall > moflist.txt & for /F %%s in (moflist.txt) do mofcomp %%s

What's the difference between the two? I used the line from link #2 (%%s), but I got the error "%%s was unexpected at this time."   I understand from other posts that using "%%s" in batch files will not yield errors.  When I used the line from link #1 (%s), the command ran.

If both lines get executed successfully, whether via CMD or BAT files, would they have the same end result?

Thank you very much.
Jee SoonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
It's simple.  a single % is used when using the for command alone on the command line.  When using the for command in a batch file, you must use %% instead.  Try it:

from the command line run (replace 192.168.1. with your local subnet):
for /l %a in (1,1,100) do @ping -n 1 -w 100 192.168.1.%a | find /i "reply"

Open in new window

Now try the same as batch file.
It shouldn't work.
Now fix the batch file and double the % and run it.
It should work fine.

And this only applies to the for command as far as I've ever seen.  you DO NOT double % for referencing command line variables -
%%computername%% is wrong no matter how you want to use it.  It's always %computername%.
Likewise, %1 in a batch file refers to the first parameter after the command.  For example, run the batch file named "runme.cmd" with echo %1 as the contents will result in "Hello" being displayed (spaces as delimiters).  (assuming you run "runcmd Hello World" without quotes.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jee SoonAuthor Commented:
Thank you so much, Lee!!!
Exactly the answer that I needed.

Thanks a lot too for the easy-to-understand, ready-to-run examples.

Looking forward to future interactions! :)
Jee SoonAuthor Commented:
Thank you, Lee!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.