FOUNDATIONS PHASE 2 · 20
Shell / PowerShell:你輸入一行 Command,OS 到底做了什麼?
Shell 是你和 OS/process 世界之間的 command environment。真正重要的是 current working directory、command resolution、stdin/stdout/stderr、pipe、exit code。
Learning outcomes
- 能區分 shell 與被啟動的 process。
- 能解釋 cwd / path resolution。
- 能使用 pipe / redirect 思考資料流。
- 能用 exit code 判斷 command success/failure。
1. Shell 啟動別的程式
PS C:\Project> node server.jsPowerShell 解析 command,找到 Node executable,啟動 Node process;PowerShell 本身不是 Node runtime。
2. Current Working Directory
Get-Location
Set-Location D:\Projects\AppRelative path 通常以 cwd 為 context,因此「檔案明明存在」但 command 找不到,常是 cwd 不同。
3. stdout / stderr
npm run build
# normal output → stdout
# errors/diagnostics → stderr兩個 stream 都是 process 對 caller 的 evidence。
4. Pipe
Get-Process |
Where-Object {
$_.CPU -gt 10
}PowerShell pipe 傳遞的是 objects;傳統 Unix shell 常以 text/bytes 為主。概念共同點是把上一個 command output 接到下一個 command input。
5. Exit Code
npm run check
# success → typically 0
# failure → non-zeroCI 就是利用 exit status 決定 step pass/fail。
Project checkpoint:Course Workspace CLI
cd project
npm install
npm run check
npm run build
Evidence:
cwd
stdout/stderr
exit code
dist/ artifactDebug evidence:Command Not Found
- command 拼字?
- executable 是否安裝?
- PATH 是否包含它?
- PowerShell variable 是否真的是 command path?
Knowledge check
- PowerShell 和 Node 是同一層嗎?
- cwd 如何影響 relative path?
- pipe 代表什麼資料流?
- CI 為什麼在意 exit code?