您的位置:首页 > 运维架构 > Linux

Linux资源管理之cgroups简介

2015-08-03 23:57 525 查看
Windows PowerShell Language Quick Reference

 

Native Support for Different Type Systems

Windows PowerShell adapts WMI, XML, ASDI, <city w:st="on"><place w:st="on">ADO</place></city>, and COM objects to provide a common syntax to access their properties and methods.  

Example
$g = Get-WmiObject Win32_Process

$g[0].Name  # instead of $g[0].Properties[“Name”]

 

Arithmetic Binary Operators

+

addition, concatenation

-

Subtraction

*

multiplication, string repetition

/

Division

%

Modulus

 

Array Operations

Does this array have a <metricconverter w:st="on" productid="3 in">3 in</metricconverter> it

1,2,3,5,3,2 –contains 3

Return all elements equal to 3:

1,2,3,5,3,2 –eq 3

 

Return all elements less than 3:

1,2,3,5,3,2 –lt 3

 

Test if 2 exists in collection:

if (1, 3, 5 –contains 2) …

Other operators:  -gt, -le, -ge, -ne

 

Arrays

“a”,“b”,”c”

array of strings

1,2,3

array of integers

@()

empty array

@(2)

array of 1 element

1,(2,3),4

array within array

,”hi”

Array of one element

$a[5]

sixth element of array*

$a[2][3]

fourth element or the third

 

element of an array

$a[2..20]

Return elements 3 thru 21

·        Arrays are zero based.

 

Assignment Operators

=, +=, -=, *=, /=, %=

 

 

Associative Arrays (Hashtables)

$hash = @{ }

Create empty hashtable

$h =@{foo=1;bar=2}

Create and initialize a hashtable

$hash.key1 = 1

Assign 1 to key “key1”

$hash.key1

Returns value of key1

$hash["key1"]

Returns value of key1

Boolean Values and Operators

TRUE

FALSE

$TRUE

$FALSE

Any string of length > 0 except the word “false”

Empty string or the string “false”

Any number !=0

Any number = 0

Array of length > 1

Array of length 0

Array of length 1 whose element is TRUE

Array of length 1 whose element is FALSE

A reference to any object

Null

Break (Scripting)

The break commands exits a loop. It can take an optional LABEL to break to

Example:

while (1)

{        $a = something

          if ($a –eq 1) break;

}

 

Command Expansion Operators

$( )

Returns null

$(1,2,3)

Returns an array containing1,2,3.

$(Get-Alias a*)

Returns evaluation of the expression

@(Get-Alias;Get-Process)

Executes the two commands and returns the results in an array

Comments

# This is a comment because # is the first char of a token

$a = “#This is not a comment…”

$a = “something” # …but this is.

Write-Host Hello#world

 

Comparison Operators

-eq

Equal

-ne

Not equal

-gt –ge

Greater than, greater than or equal to

-lt –le

Less than, less than or equal to

 

“i” or “c” may be prepended to get case-insensitive or case-sensitive operations (for example, –ceq )

Continue (Scripting)

The continue statement continues the next iteration of a loop without breaking out of it. Example:

while (1)

{               $a = something

      if ($a –eq 1) (continue)

      # This line is not reached unless $a == 1

}

#  This line is never reached.

Dot Sourcing

Dot sourcing allows running functions, script blocks, and scripts in the current scope rather than a local one. Example:

. MyFunction

 

If MyFunction sets a variable, it is set in the current scope rather than the function’s local scope.

$a = {$x = Get-Process | Select –First 2}

. $a    #Evaluates the script block in the current scope

 

Escape Sequences

The Windows PowerShell escape character is the backwards apostrophe, or `.  To make a character literal, precede it with `.  To specify a ` use ``.

Special escape sequences

`0

(null)

`a

(alert)

`b

(backspace)

`f

(form feed)

`n

(new line)

`r

(carriage return)

`t

(tab)

`v

(vertical quote)

 

Execution Order

Windows PowerShell attempts to resolve commands in the following order: aliases, functions, cmdlets, scripts, executables, and normal files.

 

For (Scripting)

[:label] for ([initializer]; [condition]; [iterator]) {}

 

Example:

for ($i = 0; $i –lt 5; $i++) {Write-Object $i}

 

Foreach (Scripting)

[:label]

foreach (identifier in collection) {}

Expression | foreach {}

Expression | foreach {BEGIN{} PROCESS{} END{}}

 

Examples:

$i = 1,2,3

foreach ($z in $i) {Write-Object $z}

Get-Process |foreach {BEGIN{$x=1}

       PROCESS{$X++}

       END{“$X Processes”}}

 

Functions (Scripting)

function MyFunction {

      write-object $args[0]

}

 

function test ([string]$label=”default label”,[int]$start=0)

{ BEGIN {$x=$start} PROCESS {“$label: $_”’; $x++}

     END{“$x total”}

}

Filters (Scripting)

padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 216pt; padding
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: