「Windows/powershell」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→変数) |
|||
| 行9: | 行9: | ||
/tmp/hoge.ps1 | /tmp/hoge.ps1 | ||
echo 'hoge' | echo 'hoge' | ||
| + | |||
| + | ==powershellバージョン確認== | ||
| + | $PSVersionTable | ||
| + | <pre> | ||
| + | Name Value | ||
| + | ---- ----- | ||
| + | PSVersion 7.1.3 | ||
| + | PSEdition Core | ||
| + | GitCommitId 7.1.3 | ||
| + | OS Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 | ||
| + | Platform Unix | ||
| + | PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} | ||
| + | PSRemotingProtocolVersion 2.3 | ||
| + | SerializationVersion 1.1.0.1 | ||
| + | WSManStackVersion 3.0 | ||
| + | </pre> | ||
| + | |||
==変数== | ==変数== | ||
2021年8月18日 (水) 17:19時点における版
目次
powershellインストール
macであれば、powershell-x.x.x-osx-x64.pkg をDL
macでpowershell実行
$ /usr/local/bin/pwsh /tmp/hoge.ps1
/tmp/hoge.ps1
echo 'hoge'
powershellバージョン確認
$PSVersionTable
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
変数
$path = "hoge.txt";
変数で定義したpathを使用
$path = "hoge.txt"; $data = Get-Content $path
テキスト文置換
aaaをcccへ置換
$data = Get-Content hoge.txt | % { $_ -replace "aaa", "ccc" }
$data | Out-File hoge.txt
参考:https://teratail.com/questions/290149
エスケープ文字対応
[]などは、\でエスケープする
$data = Get-Content hoge.txt | % { $_ -replace "aaa\[hoge\]", "ccc[piyo]" }
