782 questions
2
votes
1
answer
77
views
Is there a functional difference between piping a variable with printf vs using parameter expansion in a heredoc?
Is there a functional difference when piping a shell variable with printf or using a heredoc and expanding the variable inside the heredoc?
Piping:
txt=…
printf '%s\n' "$txt" | xxd
Heredoc:
...
2
votes
1
answer
39
views
Adding variables in PHP 8.2 heredoc not working
I'm using PHP 8.2. I have the following heredoc:
$a = 4;
$b = 2;
$str = <<<EOT
$a + $b = {$a + $b}
EOT;
print $str;
Error:
PHP Parse error: syntax error, unexpected token "+", ...
4
votes
4
answers
208
views
Is there something better than <<- EOF in bash?
I recently tried to use the <<- operator for heredocs in bash to keep indentation in my bash functions:
cat <<- EOF
Hello World
EOF
However it turns out this only strips literal tab ...
0
votes
1
answer
141
views
Heredoc Strings are shown as new Change but they aren't
I created some Terraform code for Uptime Checks in Google Cloud Plattform.
But after doing an terraform plan the content_matchers block content attribute is always shown as something Terraform is ...
-1
votes
2
answers
80
views
How to do a for-loop within a here document?
I am trying to create a shell script that goes multiple times through a program and calculates me some physical parameters. The program is opened in the console with "./radex" and afterwards ...
0
votes
1
answer
47
views
Unindent and convert multiline string to single line [duplicate]
I have several multiline strings with indentation in my code, such as this (simplified example):
def foo():
cmd = '''ls
/usr/bin
/usr/sbin
/usr/...
1
vote
1
answer
659
views
Run program after heredoc in same RUN statement in Dockerfile
I would like to create a file using heredoc and then run a command after in the same RUN statement in a Dockerfile.
To illustrate, take this Dockerfile
FROM alpine
RUN export FOO=bar && \
...
0
votes
0
answers
29
views
ssh into remote servers, get systeminfo and print out in local terminal [duplicate]
I have the following script and when I run it, I don't get the expected output to the local terminal.
I am assuming it must be the variables that I am assigning in the heredoc that is not getting ...
0
votes
1
answer
182
views
Alternatives for heredocs in bashscripts? External templating? [duplicate]
I currently use many heredocs in bash scripts.
These heredocs contain bash variables, e.g. ${MY_VAR}, which are substituted as the script executes and the heredoc is read.
Some of these heredocs have ...
0
votes
1
answer
325
views
Why are class constants not allowed in heredoc?
I want to use a class constant in heredoc which is used in an annotation, but that gives me an error.
class Example {
#[MyAnnotation(schema:<<<YAML
type: {${MyOtherClass::A_CONSTANT}}
...
1
vote
3
answers
946
views
Transfer file via ssh with only echo and cat command
Due to some constraints, i have to transfer local file to remote ssh with only echo and cat command and here-document.
I've tried:
#!/bin/bash
SSH_CMD=xxx # suppose `SSH_CMD` is my ssh command
w="...
0
votes
0
answers
32
views
heredoc php functions for select element
I understand that calling PHP functions within HEREDOC strings can be tricky and I have looked at some of the previous answers on here and tried to implement them without success.
I have a function ...
0
votes
3
answers
349
views
how to display $ in bash script
I have a script. I can't print $ in a screen.
#!/bin/bash
SERVER_IP=""
PASSWORD=""
DOMAIN=""
CONFIG_CONTENT=$(cat << EOF
server {
listen 80;
listen [::]:...
2
votes
3
answers
417
views
Process substitution with heredoc works in zsh. How to make it work in bash?
I want the ability to pass a heredoc to the source command for local interpretation.
The body of the heredoc document will be injected later before calling the script, and can be multiline.
I came up ...
0
votes
1
answer
254
views
How to make a command stop expecting input if heredoc delimiter is ""?
In a POSIX shell (let's consider bash in this example), whenever we run cmd << eof, the shell expects input until a string containing only eof is received. Also, the standard states that:
If ...