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.

0
votes
0answers
23 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
33 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
36 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
69 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
54 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
53 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
55 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
96 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
116 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
71 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
55 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 ...
2
votes
1answer
240 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
184 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
193 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
106 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
358 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
352 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
507 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
204 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
54 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
211 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
59 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
77 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
113 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
3answers
761 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
491 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
471 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
529 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
58 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
66 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 ...
1
vote
2answers
292 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
74 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
583 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
188 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 ...
-2
votes
2answers
226 views

Inject commands to crontab -e?

Edit: I use Debian stable 9.3. I have the following code which is aimed to run inside root's crontab: 0 0 * * * /opt/cron_daily.sh 0 0 * * 0 /opt/cron.weekly.sh Of course I can manually copy it, ...
0
votes
1answer
32 views

Trying to place the name in the text of a file

I am trying to put the name of the file I just made in my script into the text of the file, but I can't seem to find how to let it print out the $name in the file. Can someoene help me? cat <<'...
0
votes
1answer
58 views

Cannot write text in a file when using here-document [duplicate]

This command doesn't seem to work in my script, how can I decide in which file I want this text, if I just create a file with the following command touch $name I want the text to be in the file $...
5
votes
2answers
634 views

Why does a 'sudo -i' login shell break a here-doc command string argument?

In the sequence of five commands below, all depend on single-quotes to hand off possible variable substitution to the called bash shell rather than the calling shell. The calling user is xx, but the ...
0
votes
1answer
701 views

How can I run patch through a heredoc in bash?

I'm trying to patch a file like this in bash: cat << ''EOF | patch --dry-run > --- urancid 2017-12-06 09:56:33.000000000 -0600 patch --dry-run > +++ /tmp/urancid 2017-12-06 15:...
1
vote
1answer
152 views

Variable value gets printed with heredoc execution [closed]

While in /var/www/html I executed the following cat heredocument which serves as a maker - It makes the file /opt/dwa.sh which includes a function and a MYSQL heredocument. cat <<-"DWA_INSTALL" ...
-1
votes
1answer
325 views

Heredocument indented inside a function fails on execution

I have this a script containing a function and a function call. Inside the function there's an heredocument: #!/bin/bash DWA() { ...... mysql -u root -p <<-MYSQL ...... ...
1
vote
1answer
42 views

cat heredocument copied everything besides function call

I executed the following code in my Bash console in an Ubuntu 16.04 environment: cat <<-'DWA' > /opt/dwa.sh DWA() { test='test' read domain find /var/www/html/ -...
5
votes
1answer
8k views

Bash 'unbound variable' error when variables are referenced in multiline comment (set -u) [duplicate]

I have an unexpected behaviour- following snippet fail with 'unbound variable' error: #!/bin/bash set -u <<EOF a=a b=$a EOF Tested on: GNU bash, version 4.4.12(1)-release GNU bash, version 4....