操作系统自用1 bash powershell基本命令

OS Programme Lecture #1  Windows PowerShell Scripting

1. 我建议 Visual Studio Code 在Windows系统中使用

2. powershell basics
>get-help
>get-command
>get-command get-*
>get-command *process

3. bash commands and re-direction:
>pwd 
>date
>cd
>ls
>dir
>dir > filelist.txt
>cat filelist.txt
>cp filelist.txt filelist2.txt
>rm filelist2.txt
>mv filelist2.txt filelist3.txt
>dir
>dir >> filelist.txt
>echo 'Welcome to OS lecture'
>echo 666
>'Hello World' > fqb.txt
>'Hello' > fqb.txt
>'World' >> fqb.txt

4. pipe: |
>echo 8 5 3 7 | measure-object -sum -max -min -average
>echo 'Hello World' | measure-object -Property length -sum
>cat .\filelist.txt | measure-object -Property length -average -sum -max -min
>'Hello World' | out-file hello.txt
>'Welcome to OS' | out-file hello.txt -append
>ls | sort

5. variable: $
>$name="Qinbing Fu"
>$port=8081
>$file1="fqb.txt"
>$file2="fqb2.txt"
>cp $file1 $file2
>ls

>$today="Thursday"
>echo 'Today is $today'
>echo "Today is $today"

>$v1="the covid in guangzhou"
>$v2=$v1
>echo $v2

6. Arithmetic
>6/2
>6/25
>1+2
>2*2
>$x=2
>$y=4
>$x+$y
>$z=$x*$y
>$z
>$w=$x/$y
>$w
>$v=1,2,3
>$v

7. Process Management simple
>get-process
>get-process -name *notepad*
>stop-process
>stop-process -name *notepad*

8. Control Structure: if
-eq equal to
-ne not equal to
-lt less than
-le less or equal to
-gt greater than
-ge greater than or equal to
see code in if.ps1

9. Control Structure: switch
see code in switch.ps1

10. Control Structure: while
see code in while.ps1

11. Control Structure: do until
see code in until.ps1

12. Control Structures: for, foreach
see code in for.ps1, foreach.ps1

13. Functions and Arguments
see code in arguments.ps1

作业 #1:
用shell script编写程序: 从控制台输入两个数,显示他们的整型的和

作业 #2:
用shell script编写程序: 编写一个带有控制语句的脚本,从控制台输入一变量,每次加一个常量到变量,显示每次结果,直到变量大于100并显示“variable limit reached”

标注:本文为广大操作系统实验课课件,最终归属权广大。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值