Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [here-document]

The tag has no usage guidance.

1
vote
0answers
18 views

How do EOD and EOF work together in Terraform?

This is the script from my terraform course provisioner "local-exec" { command = <<EOD cat <<EOF > aws_hosts [dev] ${aws_instance.dev.public_ip} [dev:...
0
votes
2answers
29 views

Bash - here doc read input value from another user

I have a here document inside a bash script. I want to read a value from it like that : su myUser<<SESSION set -x echo -n "Enter your name and press [ENTER]: " read name echo "the name is $...
2
votes
1answer
57 views

Pass variable to cat [duplicate]

I have only one variable in bash script ${PHP_V} and trying to pass in nginx config file like: cat <<'EOF' > /etc/nginx/sites-available/default server { listen 80 default_server; ...
3
votes
1answer
35 views

How to use here document or assign multiline string to variable in csh?

I want to assign to variable to a multi-line string that contains a variable and then echo it. I attempted using here-doc as shown below. What is the best way to achieve this in csh? set my_name="...
2
votes
1answer
37 views

Perl Script in Bash Here Document (does not output variable)?

How come the following perl code, mkdir("foo"); print "foo: $!\n"; mkdir("foo"); print "foo: $!\n"; Will output the following (in a directory without a foo) perl ./asdf.pl foo: foo: File exists ...
0
votes
3answers
49 views

create single string argument using heredoc or other technique

I am trying to execute a script on remote servers, passing the script as the last argument ntrs exec-all-ubuntu --exec `cat << 'EOF' echo "$(pwd)" echo "$foobar" EOF` The problem is that ...
0
votes
2answers
99 views

How to feed data through pipe into utility/command as part of shell here-doc?

The following example is kind of classical way of using pipes. On right side of pipe we have a "simple" utility which reads data from stdin (pipe) and prints to stdout in reverse order: { cat <<...
0
votes
2answers
111 views

Using Heredoc in a Makefile. Is it Possible?

I'm using Makefile such that the default step is to print out a help document for the other options. It would be great if I could add an EOF section instead of multiple echos. Is it possible to use ...
1
vote
1answer
71 views

`cat` behaves strangely on a mounted virtio directory

When I'm in a mounted directory (9p) on my gentoo-guest and do the following: TMPDIR='./foo' # The directory './foo' exists and the name 'TMPDIR' is important cat <<EOF hello world EOF I get ...
0
votes
0answers
26 views

How to set variables in nested ssh session

I want to set some variable in ssh session which is nested. ssh host1 << EOF ssh host2 << EOF1 myvar="Hello" echo=\$myvar EOF1 EOF What is wrong in this bash ...
0
votes
1answer
35 views

sudo redirection doesn't work when in a function

I have a script which writes some content into a file with cat and EOF. While this thing works within a bash script, it doesn't work if I put it inside a function. Working code: cat << EOF | ...
0
votes
0answers
40 views

Pass local variable over here-document

I have a shell script which does couple of jobs with a here-document. But, we are unable to get the variable expanded on remote host. USER=prod ssh -o StrictHostKeyChecking=no -t <app_host> &...
1
vote
1answer
82 views

Stop CTRL+C Exiting Local Script Which is Running tcpdump in Remote Machine

I have setup a simple script like the below: sshpass -p $password ssh -T $username@$ip_address -p 30007 <<- EOF > $save_file.pcap sh tcpdump -i eth5.1 -s 0 -n -v -U -w - EOF sed -i '...
0
votes
0answers
61 views

Bash Scripting not able to parse remote SSH commands correctly

I'm trying to build a script to scp somefiles to another machine, but I'm trying to do some checkups before starting the actual SCP. One of the checks is to see if there are somefiles (collectl raw ...
0
votes
1answer
59 views

How to Pipe Segment of Heredoc Output to Local File

I am issuing a command to a remote device in order to run a tcpdump on one of it's interfaces, but capture the output to a local .pcap file on my Ubuntu VM. The command that I'm issuing is as follows: ...
0
votes
2answers
84 views

how to execute multiple lines of code inside SSH in bash script

I want to execute below code,but it is highlighting error in code with red in vi. Getting error after sudo ssh -t root@$ip << EOF line .Where have I scripted wrongly? #!/bin/bash cassandra_home=...
1
vote
1answer
124 views

Define variable using read from stdin of heredoc

I am trying to store Available and Total Memory into variables in a script file as follows, read -r Available Total <<EOT $(free -m | awk '/^Mem/{print $7; print $2;}') EOT $ echo $Total $ ...
1
vote
1answer
214 views

diff between END and EOF

Is there any difference between: cat <<END {"@json-stdio":true,"value":"$pack"} END and cat <<EOF {"@json-stdio":true,"value":"$pack"} EOF ?
1
vote
2answers
73 views

Can I use << EOF but let user complete the input

The need for this arose from the script below. It connects to a remote PC using anyconnect's vpn utility. First it asks for the one-time-password, connects, starts an RDP client and disconnects after ...
1
vote
0answers
77 views

Using a here-doc with trailing backslashes inside a process substitution in bash

This: cat <<EOF one two three EOF Prints: one two three And this: cat <<EOF one \\ two \\ three EOF Prints: one \ two \ three But while this: cat <( cat <<EOF one two ...
3
votes
1answer
294 views

What are the differences between here document and here string in their purposes? [closed]

In bash, it seems to me both here document and here string can be used for providing strings as stdin inputs. here document may provide an extra features to specify delimiter, which I am not sure if ...
0
votes
3answers
218 views

Why does double quoting an array expansion in here document not seem to work here?

I have two arrays $ arr1=( 1 2 2 3) $ arr2=( 2 3 3 4) Why does this generate strange output when I follow the good practice of double quoting an array expansion $ tsort << EOF > "${arr1[@]}...
2
votes
1answer
245 views

Using heredoc in zsh aliases

I would like to use heredoc in a zsh alias, for example: alias runthing="cd ~; date << HERE date HERE" However every time I run this alias, the shell acts as if I have not terminated the ...
1
vote
3answers
147 views

Possible to declare function locally and use it at the remote end of an SSH connection

I am looking to create a function in a script locally, and call it on a remote host, over an SSH connection, is this possible? set -e gitpull () { cd /var/www/html STATUS=$((git status) 2>...
2
votes
3answers
387 views

grep with heredoc in function

I want to make function that parses from text pasted in a terminal. $ cat <<eof | grep --color sometext > foo > sometext > sometext1 > a sometext > asdf > > eof sometext ...
2
votes
3answers
414 views

How to escape a character in a heredoc bash script

I have a bash script which read an input file and using a heredoc to ssh to a server using expect, but am having issue escaping some special character in the input file. Here is what I have.. I have ...
-1
votes
1answer
2k views

Why does echo <<EOF … EOF not work [duplicate]

Just wondering if anyone can explain why this works: echo `cat <<EOF {"branch":"foo","value":"bar"} EOF` but this doesn't: echo <<EOF {"branch":"foo","value":"bar"} EOF (the second ...
1
vote
1answer
562 views

Bash file: No such file or directory [duplicate]

I have the following script ssh user@host << EOF STATUS="$(git status)" SEARCH_STATUS="Not a git" if [[ "$STATUS" == *$SEARCH_STATUS* ]]; then echo "Not a git repository" ...
0
votes
2answers
242 views

gnuplot, here-documents, and command line arguments

Can I use a here document to pass a gnuplot script to gnuplot and also have commandline line arguments passed to gnuplot? In my bash file, I would normally write: #!/bin/bash #set up code in here... ...
-1
votes
1answer
55 views

An heredocument without a delimiter

In this post, Stephen's answer displays this code: cat <<-"EOF1" >> myPath/myFile.append if ! grep -F -q -f myPath/myFile{.append,}; then cat myPath/myFile.append >> myPath/...
1
vote
0answers
75 views

A utility to append content into a file, if this content isn't already in the file (even in part)

Is there a *Nix utility by which I could append content to a file (say, append the content of a template file into the end of a second file), only if the content isn't already available in the second ...
2
votes
2answers
217 views

Append heredocument content to a file, only if this content doesn't already exist in that file

I have a file to which I want to append some content (including the first, second and third empty spaces visible in my code below): ### I am text 1 ### I am text 2 (The actual text I append is way ...
-1
votes
2answers
60 views

Using regex in the heredocument redirect/append line, to target specific “sets” of directories

I need a way to target all sub directories under public_html which ends with .com or other TLDs like .biz or .co.il I might list, in a heredocument. This my hereoducmnet inside an pushd-popd - if-fi ...
1
vote
2answers
85 views

why <<\END is used in ed [duplicate]

Using ed put character # to the beginning of lines 10 to 20 in file /etc/passwd. Solution is the following ed /etc/passwd <<\END 10,20s/^/#/ %p Q END my question is that what does << ...
11
votes
4answers
3k views

Why is the JSON content from heredoc not parsable?

I have a JSON fragment. The following does not work: VALUE=<<PERSON { "type": "account", "customer_id": "1234", "customer_email": "jim@gmail.com" } PERSON echo -n "$VALUE" | python -m ...
2
votes
1answer
127 views

Here-document with cat

I am new to Linux, shell scripting, and I'm trying to learn the fundamentals. I am currently on the redirection chapter, where here-documents are being explained. I could not really understand how the ...
1
vote
4answers
897 views

How to deal with multiline strings and string interpolation?

Say I want to have a template somewhere which is multiline string: I have some text with ${placeholders} in this and some ${different} ones ${here} and ${there} What would be my best way of ...
4
votes
1answer
512 views

Using a function's output (defined locally) inside SSH call

I have created a function function getqueue() { urlqueuename="urlcall" ouput=`curl $urlqueuename` queue=$(echo $ouput | jq -r '.queueName') echo $queue } I am using a ssh call ...
0
votes
4answers
2k views

Running a script file over ssh through sudo

I can log in to a remote machine as a user who can do sudo su -. I can't login as root. I have a script locally that I want to run at the remote machine. Also, the script is sent there trough another ...
1
vote
3answers
2k views

Using /dev/stdin and a heredoc to pass a file from the command line

I'm curious about the theory behind how heredocs can be passed as a file to a command line utility. Recently, I discovered I can pass a file as heredoc. For example: awk '{ split($0, arr, " "); ...
1
vote
1answer
540 views

Here-document not working properly on shell script

I have two files: server.sh and client.sh, the server sends the following text to the client client.sh porta_cliente=5678 porta_servidor=8765 nc -l $porta_cliente | sh server.sh porta_cliente=...
5
votes
2answers
1k views

Bad substitution: no closing “`” in a heredoc / EOF

I'd like to print a man style usage message to describe a shell function like this output man find: NAME find - search for files in a directory hierarchy SYNOPSIS find [-H] [-L] [-P] [-...
0
votes
1answer
564 views

mv command on remote server not working

B=$1 CHECK="$(ssh $USER@$LOGINHOST <<EOD . /path/loadprofile.sh if [[ ! -e \$TXTDR/$B.txt ]]; then; echo "TXT file for this job does not exist."; exit; fi mv \$TXTDR/$B....
8
votes
2answers
2k views

A while loop and an here-document - what happens when?

I have this while loop and here-document combo which I run in Bash 4.3.48(1) and I don't understand its logic at all. while read file; do source ~/unwe/"$file" done <<-EOF x.sh y.sh EOF ...
1
vote
1answer
61 views

How to use one path in heredocument

I wrote this here-document to source a few scripts under the path ~/own_scripts/ but I wrote it in a way that causes duplication of this path: source <<-EOF ~/own_scripts/1.sh ~/own_scripts/...
0
votes
1answer
69 views

variable values filling not working in bash

I have the following bash script: #!/bin/bash $db=DB $H=6973 $cov=38 for i in $(find . -type f -name "*.*.las"); do cat <<EOF #qsub <<EOF #!/bin/bash -l #PBS -N DASqv #PBS -l ...
2
votes
2answers
335 views

From multiline heredocument to a uniline herestring, with line breaks

I have this multilinie heredocument which I desire to translate into a uniline herestring: cat <<-"PHPCONF" > /etc/php/*/zz_overrides.ini [PHP] post_max_size = 200M upload_max_filesize ...
-3
votes
1answer
75 views

Create/change a file and source it - both in one line

I desire a command that creates/changes some file and then source that file, all in one line, in Bash. It's important for me to know if it's possible (or why it isn't), as this could help saving a ...
1
vote
5answers
616 views

How to append multiple lines to a file, if these lines doesn't exist in that file?

How to append multiple lines to a file, if these lines doesn't exist in that file? For example, to add multiple global aliases to /etc/bash.bashrc I use an heredocument: cat <<-"BASHRC" >&...
0
votes
1answer
205 views

Redirect to crontab with an heredocument

Is it possible to print to crontab with an heredocument? I tried these but failed: cat <<-"CRONTAB" > crontab 0 0 * * * cat /dev/null > /var/mail/root 0 1 * * 0 certbot renew -q ...