Questions tagged [herestring]

Multiline string literals that use similar syntax, preserving line breaks and other whitespace (including indentation) in the text.

50 questions
0
votes
1 answer

Expand variable within here-string in single quote using powershell

I have a scenario where I am using here-string with single quotes since I need to print the variable as it is and also expand certain variables within it. Can you please suggest how I can achieve this? $S3BucketName = "Dynamically generated" $file =…
Dhillli4u
  • 117
  • 12
0
votes
1 answer

oc exec with heredoc: cannot pass variable into command to execute in container; rpc error: code = 2 desc = oci runtime error

I want to use oc exec to execute a cat in my pod. In this cat command I need to expand some variable. cat /opt/amq/data/split-$index/running So, I try this: oc exec -i $pod -- '"/bin/bash" -s <
WesternGun
  • 11,303
  • 6
  • 88
  • 157
0
votes
1 answer

Double quote and dollar prefix string in shell

In the question How to execute ssh-keygen without prompt I find they use the here string like this: ""$'\n'"y" Why do they need double quote before $? It seems $'\n'y is equal to it: bash$ cat - <<< ""$'\n'"y" | od -c 0000000 \n y \n 0000003 bash$…
leopay
  • 21
  • 3
0
votes
0 answers

Why does herestring add a newline

Well: 15:18 $ SECRET=Secret 15:24 $ echo -n "$SECRET" | base64 U2VjcmV0 15:24 $ base64 <<< "$SECRET" U2VjcmV0Cg== 15:24 $ base64 <<< $SECRET U2VjcmV0Cg== Cg== is 0a, i.e. line feed I find it very surprising, at least if you base your…
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
0
votes
1 answer

sed line number specific substitution changes every pattern on using g option and here-string

When using pipe with or without global g option gives same result: echo -e 'hi\nhello\nhi' | sed '1s/hi/hey/g' hey hello hi works for here-string as well when not using global g option: sed '1s/hi/hey/' <<< $(echo -e 'hi\nhello\nhi') hey hello…
Ibrahim Quraish
  • 3,889
  • 2
  • 31
  • 39
0
votes
1 answer

bash 3 and bash 5 evaluate herestring whitespace differently

I have a script: #!/bin/bash { read a read b } <<< $(echo a; echo b) declare -p a b I wrote it to f, did chmod +x ./f, and expected that bash ./f and ./f would be identical. They aren't: ~/dev/test[1]$ ./f declare -- a="a b" declare --…
jeremysprofile
  • 10,028
  • 4
  • 33
  • 53
0
votes
0 answers

Here string in while loop throwing syntax error

I really don't understand too much about this whole here-string thing, but according to all my research this should work. And it did. A while ago. The intended operation is to download randomly generated SALTs from the wordpress api, and insert them…
Ben
  • 1
  • 2
0
votes
1 answer

Combining process substitution with a here string

I am trying to combine the results of a command and a here string like this: cat <(echo first) <<< second I am getting this output: first Instead of first second Why?
codeforester
  • 39,467
  • 16
  • 112
  • 140
0
votes
1 answer

What does this bash script involving "read" do?

I found this in one of the bash scripts for capturing metrics running on CentOS. read -rd '' count <<< "$count" I know read reads the content of file descriptor into buffer, but I cannot find the documentation for the command line switches -r,…
duggi
  • 556
  • 5
  • 13
0
votes
1 answer

Processing output command with new lines redirected as Herestring

I'm dealing with a while loop processing a Herestring input: one_is_achieved=0 while IFS="=" read key value ; do process_entry key value && one_is_achieved=1 done <<<$(output_entries) # Dealing with one_is_achieved [...] the function…
Amessihel
  • 5,891
  • 3
  • 16
  • 40
0
votes
0 answers

Variable not expanding in double quoted here string

The variable $reperr is not expanding inside the double quoted here-string. When the scriptblock completes, $reperr does have a value, but it will not print in the here string, all i get in the body is the flat text "There are currently errors with…
200mg
  • 503
  • 1
  • 10
  • 24
0
votes
1 answer

Using enum names in a multiline string to associate each string line with the integer value of the enum. Is there a better way?

My RTF parser needs to process two flavors of rtf files (one file per program execution): rtf files as saved from Word and rtf files as created by a COTS report generator utility. The rtf for each is valid, but different. My parser uses regex…
VA systems engineer
  • 2,856
  • 2
  • 14
  • 38
0
votes
2 answers

How to use xargs with ed?

I want to batch replace strings recursively inside a folder, and I have settled with using Perl. I would like to see if there is a solution which requires less dependency and work across platforms. For listing files, I can use anything from ls to…
Sunny Pun
  • 726
  • 5
  • 14
0
votes
2 answers

Declare a here-string containing variables outside of a loop

I would like to declare a here-string outside of a loop use that string in the loop where the variables get resolved. My ideal scenario would look like below. This doesn't work as Powershell evaluates the string one time before entering the loop…
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
0
votes
2 answers

Generic "header" and "footer", to be included unchanged in a script to achieve multiline statements

To cut the chase to the point, the following (originating from a Charles Duffy's reply to a related question - see his answer) would be an acceptable format for my requirements: eval "$( { sed -E -e 's/^[ ]+//;' -e ':a;N;$!ba;s/\n//g' | tr -d…
lucid_dreamer
  • 362
  • 4
  • 9