Skip to main content

Questions tagged [here-document]

0 votes
0 answers
46 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 ...
Mika's user avatar
  • 101
2 votes
1 answer
251 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 ...
Simon Huenecke's user avatar
7 votes
2 answers
862 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 ...
merlin2011's user avatar
  • 4,179
8 votes
1 answer
910 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 ...
Yakog's user avatar
  • 517
0 votes
1 answer
86 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 ...
showkey's user avatar
  • 571
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: ...
Jason Gross's user avatar
0 votes
2 answers
161 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 ...
MortenSickel's user avatar
  • 1,443
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 "$...
pedral's user avatar
  • 121
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 ...
Cnnewb's user avatar
  • 51
5 votes
1 answer
331 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 ...
nath's user avatar
  • 6,094
0 votes
1 answer
131 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; ...
Dan Jacobson's user avatar
0 votes
2 answers
85 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 [...
Vinn's user avatar
  • 236
0 votes
0 answers
873 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. -...
George Udosen's user avatar
0 votes
2 answers
160 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/...
Erwann's user avatar
  • 729
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 ...
Evan Carroll's user avatar
  • 35.1k

15 30 50 per page
1
2 3 4 5
17