腳本定義
// script file name is "script.ps1"
// input parameter
param([string]$fileName)
// print parameter $fileName
Write-Output $fileName
腳本調用
// first way, must be passed in order.
.\script.ps1 .\MatchText.java
// second way, can be passed out of order.
.\script.ps1 -fileName .\MatchText.java
注意:
腳本中定義的變量,作用域範圍僅限腳本內,一旦腳本執行結束,存在於腳本中的變量就會銷燬。
如果一個變量定義在腳本外,沒有定義在腳本內,在腳本內使用時會把外面的變量引過來。
如果一個變量定義在腳本外,腳本內也有定義,那麼腳本內變量的改動不會影響腳本外的變量。