PowerShell modify_ script #1493
-
I'm having trouble writing a var="$(cat <&0)" For PowerShell, I tried doing: $var = while ($line = Read-Host) { $line } The issue is that this seems to also output the file contents at the same time, resulting in the output file containing both the unmodified and modified contents. Does anyone have a working sample of a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
See https://stackoverflow.com/a/66550241/11000543 regarding I can't remember off the top of my head if At the moment I'm using this: function Read-FileFromStdin {
$stdin = [System.Console]::In
$allLines = @()
while ($line = $stdin.ReadLine()) {
$allLines += $line
}
if (-not $allLines) {
return $null
}
return $allLines -join [System.Environment]::NewLine
}
$CurrentFileContents = Read-FileFromStdin You can also just directly read the file contents if you want: function Read-FileFromPath {
$filePath = "your/path/here"
if (-not (Test-Path -Path $filePath)) {
return $null
}
$allLines = Get-Content -Path $filePath -ErrorAction 'SilentlyContinue'
if (-not $allLines) {
return $null
}
return $allLines -join [System.Environment]::NewLine
}
$CurrentFileContents = Read-FileFromPath |
Beta Was this translation helpful? Give feedback.
See https://stackoverflow.com/a/66550241/11000543 regarding
Read-Host
.I can't remember off the top of my head if
$input
/$($input)
/@($input)
works in the context of a chezmoimodify_
script. Feel free to try it.At the moment I'm using this:
You can also just directly read the file contents if you want: