![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Command Line Argument Types I am retrieveing command line arguments passed to a PS1 script. I find that: a. ./myscript 5 $args[0].GetType() gives Int32 b. ./myscript -5 $args[0].GetType() gives String c. ./myscript (-5) $args[0].GetType() gives Int32 Is this how it is supposed to work? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Command Line Argument Types On Wed, 20 Dec 2006 17:58:01 -0800, John Smith <JohnSmith@discussions.microsoft.com> wrote: > I am retrieveing command line arguments passed to a PS1 script. I find that: > > a. ./myscript 5 $args[0].GetType() gives Int32 > b. ./myscript -5 $args[0].GetType() gives String > c. ./myscript (-5) $args[0].GetType() gives Int32 > > Is this how it is supposed to work? Interesting, I didn't know that. It's the same with functions, but I suppose most people would use the parentheses there out of habit and never notice it: function testit($arg){ $arg.GetType() } testit 5 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType testit -5 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object testit (-5) IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Command Line Argument Types "Lucvdv" <replace_name@null.net> wrote in message news:h56lo2h8vqnfe9tfs9nh0jgbv95ns967lk@4ax.com... <...> > It's the same with functions, but I suppose most people would use the > parentheses there out of habit and never notice it: Not a good habit. Be careful with parentheses when you pass arguments to functions. Parentheses mean that you are passing everything they enclose as *one* argument that will be evaluated as an expression: PS> function testarg { >> "`$args[0]: $($args[0])" >> "`$args[1]: $($args[1])" >> } >> PS> testarg (1,5) $args[0]: 1 5 $args[1]: PS> testarg (1 5) Unexpected token '5' in expression or statement. At line:1 char:13 + testarg (1 5) <<<< PS> testarg 1 5 $args[0]: 1 $args[1]: 5 Jacques |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Command Line Argument Types "Jacques Barathon [MS]" <jbaratho@online.microsoft.com> wrote in message news:eK7YNUUJHHA.3668@TK2MSFTNGP02.phx.gbl... > "Lucvdv" <replace_name@null.net> wrote in message > news:h56lo2h8vqnfe9tfs9nh0jgbv95ns967lk@4ax.com... > <...> >> It's the same with functions, but I suppose most people would use the >> parentheses there out of habit and never notice it: > > Not a good habit. Be careful with parentheses when you pass arguments to > functions. Parentheses mean that you are passing everything they enclose > as *one* argument that will be evaluated as an expression: I *still* get bit by that one from time to time. It might be easier to remember not to use the parens on the call if it weren't for the fact that when calling .NET methods you have to use parens (well at least the call works as expected if you do). -- Keith |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Command Line Argument Types "Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message news:uU750zdJHHA.4760@TK2MSFTNGP03.phx.gbl... <...> > I *still* get bit by that one from time to time. It might be easier to > remember not to use the parens on the call if it weren't for the fact that > when calling .NET methods you have to use parens (well at least the call > works as expected if you do). Calling any method of any object always requires parens: "hello".replace "h","c" >> won't work Jacques |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to Open notepad with a command-line argument | Daz | VB Script | 3 | 05-19-2008 05:02 AM |
| Variable arguments and argument types | Chris Warwick | PowerShell | 8 | 05-28-2007 03:43 AM |
| Re: Variable arguments and argument types | klumsy@xtra.co.nz | PowerShell | 0 | 05-23-2007 03:16 PM |
| Re: Variable arguments and argument types | klumsy@xtra.co.nz | PowerShell | 0 | 05-23-2007 03:15 PM |
| Re: Variable arguments and argument types | klumsy@xtra.co.nz | PowerShell | 0 | 05-23-2007 03:12 PM |