Questions tagged [here-document]
The here-document tag has no summary.
242 questions
0 votes
0 answers
49 views
bash variable substitution inside heredoc delimiter: how does it work? [duplicate]
For a school project, I am tasked with making my own (simplified) shell, with bash being the reference point. This includes replicating heredoc behavior which was fun until I stumbled upon variable ...
2 votes
1 answer
274 views
Using Here-Document as password Input for ssh
First, I do know this is a security risk. I do know about ssh keys and sshpass. This belongs to a fun project. I wondered if a bash Here-Document could be used as a password input for ssh. I ...
7 votes
2 answers
892 views
Is it possible to define a bash heredoc with a multi-word delimiter that expands variables?
Consider the following script: #!/bin/bash foo=Hello bar=Word cat <<EOF No quotes single word delimiter expands $foo $bar EOF cat <<'EOF' Single-quoted single word delimiter does not ...
8 votes
1 answer
933 views
Why does bash with "here documents" redirection start as interactive?
I found the following in man bash as a definition of interactive shell: An interactive shell is one started without non-option arguments (unless -s is specified) and without the -c option whose ...
0 votes
1 answer
97 views
How can I use a here-document on the left-hand side of a pipeline? [duplicate]
Show lines passed by here-document in the stdout: cat <<EOF foo bar baz EOF foo bar baz I want to match some string with grep via pipe: cat <<EOF foo bar baz EOF |grep 'ba' Why can't ...
6 votes
3 answers
1k views
How can I assign a heredoc to a variable in a way that's portable across Unix and Mac?
This code works fine on Linux but not Mac OS: #!/usr/bin/env bash foo=$(cat <<EOF "\[^"\]+" EOF ) printf "%s" "$foo" It fails on Mac with ./test.sh: line 6: ...
0 votes
2 answers
180 views
Cat file and heredoc to pipe
I do some automatic checks and want to send a mail if a file has changed. I want the mail body to contain the new version of the file, some static text and the old version of the file, so what I do is ...
11 votes
1 answer
1k views
Bash 4: unexpected EOF while looking for matching `)'
This very simplified version of my script #!/usr/bin/env bash example="$(bash -rs <<'BASH' -- 'This has been executed in restricted shell' echo "$1" BASH )" echo "$...
5 votes
3 answers
2k views
"Here Document" as a Single Line Command?
I have this command to run a checksum in some software I want to install: echo "85762db0edc00ce19a2cd5496d1627903e6198ad850bbbdefb2ceaa46bd20cbd install.sh" | sha256sum -c But I would like ...
5 votes
1 answer
341 views
How can I pass variables to a file printed from outside a bash script?
Assuming I have a variable v="c d e f g" and a file with the content: line1 $v line3 How can I make a bash script print this file with the content of the variable in line 2 as if I was ...
0 votes
1 answer
142 views
How to combine ...if $x and a here-doc in perl? [closed]
How is one supposed to write this? print <<EOF; if $x bla EOF I think it is called postfix notation, and a here-doc. I get a syntax error. OK, I guess I'll just use print "bla" if $x; ...
0 votes
2 answers
92 views
Testing for dir via ssh script - nothing happens
I usually run server scripts like this, with a here-document. But when I test if a directory exists, the script continues even though the test fails -- why? ssh $user@$ip /bin/bash <<SCRIPT if [...
0 votes
0 answers
913 views
How to use heredoc inside my ssh command
I have a bash script that connects to a remote machine via SSH and runs a series of commands. It seems that the heredoc within the outer script is not aligning properly, and I keep getting an error. -...
0 votes
2 answers
171 views
How to pass a script-file to sed as a heredoc?
This converts 'a' to 'A'. sed 's/a/A/g' <(echo "foobar") foobAr This supplies the commands necessary to make each vowel upper-case: $ cat << EOF s/a/A/g s/e/E/g s/i/I/g s/o/O/g s/u/...
0 votes
1 answer
1k views
How can I supply a heredoc to podman run?
When I run buildah, I typically use a heredoc, ctr=$(buildah from alpine:3); buildah run $ctr sh -- <<EOF apk update; apk add git; EOF buildah commit $ctr heredoc_demo; However, when I ...