Questions tagged [here-string]

A special, more compact form of the here-document consisting of <<< followed by a single WORD.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
156 views

Difference in bash 3 between pipe and here-string

If I run: IFS=':' cat <<< $(echo $PATH) then the ":" are used for word splitting and the output contains spaces instead of ":", but if I run: echo $PATH | IFS=':' cat ...
Allen's user avatar
  • 206
-2 votes
2 answers
140 views

How to use positional parameter in docker exec command with here strings (<<<)?

Here is what I am trying to do: docker exec -it $1 /bin/bash <<< $CONTAINER_ID But this doesn't work: Output: "docker exec" requires at least 2 arguments. It seems that <<...
Anton Kuznetsov's user avatar
7 votes
3 answers
2k views

How can I use the bash <<< operator with diff?

Please, observe: $ diff <(echo a) <<<b diff: missing operand after '/dev/fd/63' diff: Try 'diff --help' for more information. I know <(...) works fine: $ diff <(echo a) <(echo b) ...
mark's user avatar
  • 387
1 vote
1 answer
84 views

How can I concat results in the here document?

I have this script: while read $item; do # Some bash logic here done <<< "$({ cat /path/to/some/file; echo; })" Now I want to also use find to find the name of some directories,...
Saeed Neamati's user avatar
0 votes
1 answer
37 views

When would someone choose to use a limit string (<<-) instead of format here strings the normal way with <<<?

The - option to mark a here document limit string (<<-LimitString) will suppress leading tabs (but not spaces) in the output. What I'm wondering is why someone would want to remove the leading ...
thinksinbinary's user avatar
0 votes
2 answers
164 views

How to make a script fail when there is an error in here string?

I have a script similar to this: #!/bin/bash set -euo pipefail IFS=$'\n\t' while read -r l; do echo "${l}" done <<< "$(cat input.txt)" echo Success The command cat ...
Thomas Leplus's user avatar
2 votes
0 answers
65 views

Why does `rm writeprotectedfile <<< ""` delete the file?

The default behaviour of the GNU rm command when asked to delete write-protected files is to interactively ask whether the user wants to delete each of the files. This is quite inconvenient in many ...
leftaroundabout's user avatar
2 votes
1 answer
223 views

sed with here-string fails, but succeeds when echo output piped to sed

After updating sed to 4.4 version, sed doesn't replace spaces with commas in the output of find command given to it as here-string: sed --version sed (GNU sed) 4.4 ls -l /tmp/test/ total 0 -rw-r--r-- ...
rok's user avatar
  • 399
6 votes
2 answers
997 views

What is more efficient or recommended for reading output of a command into variables in Bash?

If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the examples below: IFS=: read user x1 uid gid x2 home shell <<<...
FedKad's user avatar
  • 580
3 votes
1 answer
423 views

backtick or Here string or read is not working as expected in RHEL 8

I am trying to redirect the output of a python script as an input into an interactive shell script. test.py print('Hello') print('world') Say test.py is as above prints "Hello world" which ...
ragul rangarajan's user avatar
1 vote
2 answers
367 views

sshpass Solaris one liner passing a command

I am trying to pass one liner sshpass command to Solaris box but won't work. those are the options I tried: sshpass -p "passw" ssh "[email protected]" -o StrictHostKeyChecking=no `...
dwt.bar's user avatar
  • 145
1 vote
2 answers
1k views

Output tee to stdout while writing to a FD using here-strings

I am trying to output tee while writing to a custom file descriptor. Example: exec 4>"/tmp/testfile.txt"; # open FD 4 tee -a >&4 <<< "Output this to stdout" # ...
kon's user avatar
  • 113
4 votes
1 answer
4k views

Why does a Bash 'while' read loop with a command substitution herestring not read the entire input?

Look at this very basic Bash script: #!/bin/bash while read l do echo $l echo "next one" done <<< $(ps aux) I have several processes on my computer, and the ps aux command works fine in ...
Bob5421's user avatar
  • 173
0 votes
0 answers
191 views

SSH tty session as a Here String

At my job, the only way that I can switch users is by doing the following: sudo su - *USER* In order to run multiple commands as the user (in a script or something), I use here strings and here docs:...
Brendan's user avatar
5 votes
1 answer
246 views

What is really happening in this command?

When I use the command cat <<< Hey > text.txt text.txt I expect it to write "Hey" in the file text.txt and then display the file. But there is no output. How is bash interpreting it ...
sh.3.ll's user avatar
  • 301
0 votes
2 answers
251 views

Ubuntu - How do I pass JSON string to herestring?

Update I noticed that I am able to pass JSON with this command command -j /dev/stdin <<< '{"key":"value"}' However, it does not work if I call it through SSH. ssh {target} 'command -j /...
Norman's user avatar
  • 139
-1 votes
2 answers
876 views

The need for $1 and $2 for comparison with an here-string

This is a follow up to this question; I don't know why but I keep misunderstanding the following code, although I try very hard to understand it: function read_and_verify { read -p "$1:" tmp1 ...
user avatar
0 votes
2 answers
534 views

What is the end of here string?

It seemed to me that the end of a here string is newline. I realize I am wrong: $ cat <<< hello world cat: world: No such file or directory What can signify the end of a here string?
Tim's user avatar
  • 99.1k
9 votes
1 answer
2k 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 ...
Tim's user avatar
  • 99.1k
6 votes
2 answers
1k views

Are Here-Strings available in ksh88?

I wanted to extract 3 words from a variable in 3 different variables in ksh script. I used this line on ksh93 and it worked fine: read A B C <<< $line Got this error for the above command ...
Pratik Mayekar's user avatar
16 votes
3 answers
25k views

Cannot create temp file for here-document: Permission denied

[Note: This similar Q concerns the same bash error message. It's been marked a duplicate of this other Q. But because I found a very different source for this error, I will answer my own Q below.] ...
Elliptical view's user avatar
3 votes
3 answers
9k views

Redirect content under a new line (without further syntax or arguments)

I tried these ways to append content to a file: printf "\nsource ~/script.sh" >> /etc/bash.bashrc echo -e "\nsource ~/script.sh" >> /etc/bash.bashrc cat >> "/etc/bash.bashrc" <&...
Arcticooling's user avatar
12 votes
2 answers
3k views

Why does wc <<<"$string" show a one-byte-longer length than printf "$string" | wc?

Accidentially, I found out that wc counts differently depending on how it gets the input from bash: $ s='hello' $ wc -m <<<"$s" 6 $ wc -c <<<"$s" 6 $ printf '%s' "$s" | wc -m 5 $ ...
rexkogitans's user avatar
  • 1,319
2 votes
2 answers
1k 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 ...
Arcticooling's user avatar
3 votes
2 answers
10k views

How to use mapfile/readarray

I have some code similar to this: while read -r col1 col2 col3 col4 col5 col6 col7 col8 TRASH; do echo -e "${col1}\n${col2}\n${col3}\n${col4}\n${col5}\n${col6}\n" done< <(ll | tail -n+...
jesse_b's user avatar
  • 36k
-2 votes
3 answers
1k views

Append herestring data to a file, if it doesn't already exist in that file (all in one line)

What will be an "elegant" one-line way to append a single line of data into the end of a file, with herestring, if this exact data isn't already in that file? This is my herestring append pattern: ...
Arcticooling's user avatar
2 votes
3 answers
4k views

How can pipe producer tell pipe consumer it has reached 'End of File'?" (un-named-pipe, not named-pipe)

I have an application which requires a producer to send filenames to a consumer, and have producer indicate to the consumer when the last filename has been sent and the end of file has been reached. ...
Craig  Hicks's user avatar
4 votes
3 answers
6k views

Variable not interpreted with 'EOF'

This is my script: var="lalallalal" tee file.tex <<'EOF' text \\ text \\ $var EOF Need to use 'EOF' (with quotes) because I can not use double slash (//) otherwise. However, if I use the ...
Marcus's user avatar
  • 49
3 votes
2 answers
7k views

Single line heredocument - Possible in Bash?

I desire to run a cat heredocument in a single row instead the natural syntax of 3 rows (opener, content, and delimiter). My need to do so is mostly aesthetic as the redirected content aimed aimed to ...
user avatar
11 votes
1 answer
1k views

What is the advantage of using bash -c over using a here string?

Is there any real benefit to using bash -c 'some command' over using bash <<< 'some command' They seem to achieve the same effect.
yosefrow's user avatar
  • 389
3 votes
1 answer
3k views

Diff between a string and a file

Basically I want to check the difference of the same file before and after a sed Tried to run: diff /opt/postTrades.sh <<< $(sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh) and diff <<&...
Moshe's user avatar
  • 312
5 votes
1 answer
16k views

Elegant way of diff'ing two variables?

I have $a and $b. I want to run diff on those. The best I have come up with is: diff <(cat <<<"$a") <(cat <<<"$b") But I have the district feeling that I am missing a clever ...
Ole Tange's user avatar
  • 33.8k
1 vote
1 answer
979 views

Assign a value to a variable inside a loop

I have this code : HOSTS="host1 host2" For hostname in ${HOSTS} ; do ssh -tt ${USERNAME}@${hostname} << EOF HOSTSN="test" echo ${HOSTSN} exit EOF Done The variable HOSTSN is empty, can ...
Issam's user avatar
  • 103
3 votes
2 answers
9k views

unexpected EOF while looking for matching `)'

I'm simply trying to get the output from a sql statement and store in bash variable. I am getting " unexpected EOF while looking for matching `)' " error. I don't see what i'm doing wrong. Why am I ...
Eternal Punishment's user avatar
1 vote
0 answers
263 views

ksh type with herestring

I wanted to use Here String in conjunction with custom type in KSH. Unfortunately I am not able to tell what I am doing wrong. #!/bin/ksh typeset -T Type_t=( typeset string='aaa' function fc { ...
Kamil's user avatar
  • 145
10 votes
4 answers
4k views

Why does cut fail with bash and not zsh?

I create a file with tab-delimited fields. echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input I have the following script named zsh.sh #!/usr/bin/env zsh while read line; do <<<$...
Sparhawk's user avatar
  • 19.6k
2 votes
2 answers
4k views

Use variables in here-string

To feed input to an interactive script, I've been using a here-string: script <<< $'1 2\n3 4\n5 6\nq' This effectively enters 1 2 3 4 5 6 q into the script. But how can I replace one of ...
snurden's user avatar
  • 317
2 votes
3 answers
1k views

Extract lines from text with string as input

How can extract lines that match the regexp string ^li from the text (not a file) below using sed or something? linux loan litmus launch I tried grep but I couldn't find a way to search within ...
stacko's user avatar
  • 771
2 votes
1 answer
196 views

Openssl generate invalid websocket security code

I need to write websocket server on GAWK. And server must handle user's Sec-WebSocket-Key by following algorithm (from RFC): Concat key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 Take sha-1 in binary ...
vladimirg's user avatar