Questions tagged [here-string]
A special, more compact form of the here-document consisting of <<< followed by a single WORD.
42 questions
4
votes
3
answers
714
views
How to remove 'newline' from 'here string'
The 'here string' (<<<) is a useful construct, and can be used in lieu of echo in many situations. However, when calculating a hash (as one example) the addition of a newline character ...
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 ...
-2
votes
2
answers
713
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 <<...
1
vote
1
answer
238
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,...
1
vote
2
answers
461
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 ...
2
votes
1
answer
279
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-- ...
3
votes
1
answer
497
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 ...
2
votes
2
answers
2k
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" # ...
0
votes
0
answers
281
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:
...
0
votes
2
answers
458
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 /dev/...
-1
votes
2
answers
670
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?
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 ...
3
votes
3
answers
11k
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" <&...
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 ...
-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:
...
4
votes
3
answers
8k
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 ...
11
votes
1
answer
2k
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.
5
votes
1
answer
17k
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 ...
3
votes
2
answers
10k
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 ...
10
votes
4
answers
5k
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
<<<$...
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 a ...