How do I pass multiple parameters into a function in PowerShell?

Parameters in calls to functions in PowerShell (all versions) are space-separated, not comma separated. Also, the parentheses are entirely unneccessary and will cause a parse error in PowerShell 2.0 (or later) if Set-StrictMode -Version 2 or higher is active. Parenthesised arguments are used in .NET methods only. function foo($a, $b, $c) { “a: $a; b: … Read more

How can I pass an argument to a PowerShell script?

Tested as working: #Must be the first statement in your script (not counting comments) param([Int32]$step=30) $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + $step } Call it with powershell.exe -file itunesForward.ps1 -step 15 Multiple parameters syntax (comments are optional, but allowed): <# Script description. Some notes. #> param ( … Read more

What does map(&:name) mean in Ruby?

It’s shorthand for tags.map(&:name.to_proc).join(‘ ‘) If foo is an object with a to_proc method, then you can pass it to a method as &foo, which will call foo.to_proc and use that as the method’s block. The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation: class … Read more

How to write a bash script that takes optional input arguments?

You could use the default-value syntax: somecommand ${1:-foo} The above will, as described in Bash Reference Manual – 3.5.3 Shell Parameter Expansion [emphasis mine]: If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. If you only want to substitute a default value if the parameter … Read more

What does the star and doublestar operator mean in a function call?

The single star * unpacks the sequence/collection into positional arguments, so you can do this: def sum(a, b): return a + b values = (1, 2) s = sum(*values) This will unpack the tuple so that it actually executes as: s = sum(1, 2) The double star ** does the same, only using a dictionary … Read more

How to pass all arguments passed to my bash script to a function of mine? [duplicate]

The $@ variable expands to all command-line parameters separated by spaces. Here is an example. abc “$@” When using $@, you should (almost) always put it in double-quotes to avoid misparsing of arguments containing spaces or wildcards (see below). This works for multiple arguments. It is also portable to all POSIX-compliant shells. It is also … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)