home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,636 of 68,980   
   Mike Sanders to Kenny McCormack   
   Re: Two simple, but related questions ab   
   09 Oct 20 13:19:17   
   
   fed44621   
   From: mike@porkchop.bsd   
      
   Kenny McCormack writes:   
   >In article <20201009-003617.309.0@Mike-Sanders.news.eternal-september.org>,   
   >Mike Sanders   wrote:   
   >>Kenny McCormack writes:   
   >>   
   >>>1) Is there a simple way to get the number of args passed to a batch   
   (.BAT   
   >>>    or .CMD) file?  Like $# in Unix.   
   >>   
   >>How about:   
   >>   
   >>@echo off   
   >>   
   >>set argc=0   
   >>for %%x in (%*) do set /a argc+=1   
   >>   
   >>echo %argc%   
   >   
   >Sure, but that's not the point.   
   >   
   >Obviously, I was asking if there was a built-in variable, like there is in   
   Unix.   
   >And the answer is: No.   
      
   [thinking to myself: umm, hyperbole from an otherwise humble guy...   
   doesnt suit him so well]   
      
   >The real underlying is that I find this strange.  Given that the DOS batch   
   >language was patterned after Unix shell (in fact, all of DOS was patterned   
   >after Unix), it is odd that they didn't put in such a variable.   
      
   %COMSPEC% < $SHELL -- A pale imitation by Microsoft if ever there was. No   
   doubt you've experienced it.   
      
   >P.S.  I see that your way is somewhat simpler than the "call nargs" method   
   >the other poster suggested.  I wonder if it (the method shown above) works   
   >when there are spaces in the args.   
      
   As written...   
      
   3 args: foo.cmd x y z   
      
   2 args: foo.cmd x "y z"   
      
   --   
   Mike Sanders   
   echo zvxr@ohflobk.ulcrezneg.arg | rot13   
   https://busybox.hypermart.net   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca