Multiline string literals that use similar syntax, preserving line breaks and other whitespace (including indentation) in the text.
Questions tagged [herestring]
50 questions
1
vote
1 answer
Task Scheduler Script with Auto-Delete
I am trying to get a script to self-delete after running, but I am having trouble figuring out the structure of the script. The script that I have works perfectly if I run it manually, but the issue is that I would then have to go back and manually…

Dust Ellse
- 71
- 7
1
vote
1 answer
PowerShell Here-String to Json
I'm attempting to convert a PowerShell Here-String to a Json file. This is a sample size of what I need to convert. I will be needing to convert a few dozen override files that can be quite long and doing this manually is not how I want to…

Keith
- 689
- 10
- 27
1
vote
1 answer
Bash command in variable with herestring as input
Using bash, I have a need to echo a series of commands before I run them. Take this example, which is nice and easy and works as expected. Note that all code examples have been run through ShellCheck which reports no issues…

David Gard
- 11,225
- 36
- 115
- 227
1
vote
1 answer
Missing file specification after redirection operator
I got the following error:
| cat << EOF > config.yaml
| ~
Missing file specification after redirection operator.`
my code in power shell is following
cat << EOF > config.yaml
serve:
proxy:
port: 4455 # run the proxy at port…

usman khan
- 59
- 1
- 7
1
vote
2 answers
How does ANSI C-Quoting in Herestrings work?
Why is this not working?
bla="
multi
line
string
"
cat -A <

Booker B
- 131
- 2
- 9
1
vote
1 answer
why can't I create a here-string in Powershell ISE?
Trying to create a here-string
> $scriptblock =@'
The string is missing the terminator: '@.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Why am I…

Roman
- 344
- 1
- 6
- 19
1
vote
1 answer
How do I pass here-string as a parameter to a powershell script in a terminal?
I have a Powershell script named "file1.ps1" as below, which works perfectly fine:
$herestring = @"
State = Defined
FiscalWeek =
"@
$hash = ConvertFrom-StringData $herestring
$hash | Format-Table
This file gives the below output:
PS C:\temp>…

user2499959
- 139
- 1
- 9
1
vote
1 answer
Append or write to file using here-strings
How can I write to a file or append a string to a file using ed only?
I have knowledge of other editors but this particular form of writing in a bash script with ed confuses me a lot:
ed fileName <<< $'a textToWriteInFile\nwq'
The previous line…

jen mueller
- 21
- 2
1
vote
2 answers
Command only getting first line of multiline here string
I'm trying to pass a here string to a command that expects three values to be passed interactively. It seems like it should be simple enough, but for some reason, the program seems to only be receiving the first line of the here string properly and…

Jared
- 91
- 1
- 8
1
vote
1 answer
Storing output of here-string BC calculation into a variable for error-checking
I have an assignment for school which is to create a script that can calculate a math equation any length using order of operations. I had some trouble with this and ended up finding out about here-strings. The biggest problem with the script seems…

OrcMan
- 69
- 10
1
vote
1 answer
How to use mutli-line commands such as here-strings when piping a script?
When playing with the -Command - option of the PowerShell executable, I came across the following limitation:
Write-Host "SETUP"
Set-PSDebug -Trace 2
Write-Host "TEST ONE"
$foo = "BAR"
Write-Host "TEST TWO"
Get-ChildItem
Write-Host "TEST THREE"
$bar…

C2H5OH
- 5,452
- 2
- 27
- 39
1
vote
4 answers
Process HereString line by line
I would like to define a HereString then work with it line by line. Initially I figured the lines would be innate in the HereString, so I could foreach ($line in $hereString), and when that didn't work I tried Get-Content $hereString. No joy in…

Gordon
- 6,257
- 6
- 36
- 89
1
vote
2 answers
Using variables in scriptblock and here-string
I started a script with script-block:
[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'qmenable' -Value 0 -Type DWord -SID $UserProfile.SID
Set-RegistryKey -Key…

François
- 11
- 2
1
vote
2 answers
One does not simply grep into ProcessBuilder
does anyone know how to use linux grep with the java ProcessBuilder? Why does this code return an empty string when it should return "sing" ?
import java.io.*;
import java.util.*;
public class Test2 {
public static void main(String[] args) throws…

burnedWood
- 93
- 1
- 9
0
votes
1 answer
Import registry from here string
Is there any solution to add(import) values to the registry from here string.
$regString = @"
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
... blha blha blha…

Agitech
- 31
- 5