linux笔记5-shell01

设置函数

function test-conn {Test-Connection -Count 2 -ComputerName $args}

装函数设置别名

Set-Alias tc test-conn

使用别名并传递参数

tc localhost

定义的变量

$a=10

$=4

计算变量

$result=$a*$b $msg="保存文本"

输出变量

$result $msg

可把一条cmdlet命令赋值给变量

$item=Get-ChildItem

powershell中交换变量值

$vluae1=10

$value2=20

$value1,$value2=$value2,$value1

查看正在使用的变量

ls variable:

查找变量

value
ls variable:"value"

验证变量value1是否存在

Test-Path variable:value1

变量会在退出powershell时自动清除,也可手动删除变量

del variable:value1

5个专用变量管理命令

Clear-Variable

Get-Variable

New-Variable

Remove-Variable

Set-Variable

posted @ 2024-06-30 16:24  alvinlyb  阅读(7)  评论(0)    收藏  举报