Questions tagged [heredoc]

A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.

A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.

See http://tldp.org/LDP/abs/html/here-docs.html

7 questions
38
votes
3 answers

How do you escape characters in heredoc?

I'm working with a bash script trying to stop it from attempting to replace variables inside my heredoc. How do set a heredoc to either A) escape the variable names instead of parsing them or B) return the entire string untouched? cat >…
Xeoncross
  • 4,449
  • 12
  • 43
  • 56
1
vote
1 answer

sudo followed by another command in ssh heredoc not working

This is my script: #!/bin/sh echo "I'm local" ssh -t -t remote.server << 'EOF' sudo echo "I'm remote and sudo" echo "I'm remote but not sudo" exit EOF This simply doesn't work, maybe because the line echo "I'm not sudo" is supplied as…
akai
  • 113
  • 5
1
vote
1 answer

How do you embed strings within the comments within a heredoc?

This doesn't work, the comment doesn't contain the IP_ADDR string SSH_UN='user' IP_ADDR='192.168.1.101' cat <<"EOF" >> .ssh/config # VirtualBox (VB) on user's laptop at $IP_ADDR Host laptopvb Hostname $IP_ADDR User $SSH_UN ForwardAgent…
hobs
  • 161
  • 7
0
votes
1 answer

Copy-paste heredocument into Bash converts tabs into dots

I use Windows 10 home (build 16299.248) and I'm SSHing into a remote Ubuntu 16.04 machine with various SSH clients (like Putty/MobaXterm). I copy-paste the following code from my personal GitHub account into an SSH session: cat <<-EOF >>…
Arcticooling
  • 1
  • 3
  • 7
  • 22
0
votes
1 answer

Use two here-documents on one line

Are two here-documents allowed to be used on one line, like in the example below? I was not able to find the documentation and cannot make the example work as expected - seeing output of both echo commands. $ ssh myhost <
dabest1
  • 252
  • 1
  • 2
  • 9
0
votes
2 answers

How to pass variables from one vm to another vm using bash script

What is the proper way to pass variable from one machine to another machine via bash script? In the below code I am trying to get the input from user and want to pass the same to remote machine, but the value is not getting accessed in remote…
loganathan
  • 240
  • 2
  • 13
0
votes
1 answer

bash heredoc and code block

Script has to log everyting in it to output and to log file Like this it works OK: #!/usr/bin/env bash some_command_1 (( echo "Some text (in parenthness too)" echo "Another text without them" ) &2>1 )|tee log.txt some_command_2 exit 0 It outputs…
Someone
  • 69
  • 6