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-string]

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

-1
votes
2answers
51 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 ...
0
votes
2answers
115 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?
3
votes
1answer
270 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 ...
6
votes
2answers
559 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 ...
6
votes
3answers
5k 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.] ...
3
votes
3answers
1k 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" <&...
11
votes
2answers
2k 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 $ ...
1
vote
2answers
305 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 ...
0
votes
2answers
2k views

How to read a mapfile

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+...
-3
votes
3answers
111 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: ...
2
votes
3answers
1k 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. ...
2
votes
2answers
1k 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 ...
1
vote
2answers
2k 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 ...
11
votes
1answer
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.
1
vote
1answer
823 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 <<&...
0
votes
1answer
3k 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 ...
1
vote
1answer
636 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 ...
2
votes
2answers
2k 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 ...
1
vote
0answers
199 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 { ...
10
votes
4answers
2k 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 <<&...
1
vote
2answers
1k 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 ...
2
votes
3answers
396 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 ...
1
vote
1answer
139 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 ...