What is the powershell equivalent to the Linux command:
tee file.txt <<EOF
Where the terminal <input>
would be something like:
blah blah <\n>
beh ble <\n>
EOF
Let's say that I copy the 3 lines above, and then enter some (yet-unknown) powershell command. Then paste into the terminal. (Presumably hitting Ctrl-D at the end of input, after the paste operation.) Then hoping to find all this in the file, file.txt.
I suppose we have to:
- Get-terminal input for $file and the unknown command, A.
- Wait for pipe input from shell.
- Wait for Ctrl-D and interrupt (EOF) shell input.
- Pipe the input buffer to the $file, using unknown command, B.
EDIT: 2020-01-17
I realize I missed my own point (in point 3) in the above list. The point was to not have to type Ctrl-D and instead have the shell look for the "EOF" sequence, just like the Linux bash command above does. This is done all the time in bash scripts, for creating configuration files and even other bash scripts. A feature which would be very useful also in PWSH.
The closes I've been able to get to the above, is by using the Tee-Object and "here" operator (@'...
), like this:
$ @"
>> Even if you have not created a profile,
>> the path of the profile file is:
>> $profile.
>> "@ | Tee-Object -FilePath "test.txt" -Append
Even if you have not created a profile,
the path of the profile file is:
C:\Users\XXXX\Documents\PowerShell\Microsoft.PowerShell_profile.ps1.
But I want the tee on the left and the here-is on the right, as the last part of the command. This would essentially complete the equivalent command. The here string in Linux is quite well explained in this answer.
fill a here string using some command
? the herestring in bash is filled from the shell script file or keyboard and not from any commands