bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unclosed quotes on heredoc mode


From: Greg Wooledge
Subject: Re: Unclosed quotes on heredoc mode
Date: Wed, 17 Nov 2021 13:54:03 -0500

On Wed, Nov 17, 2021 at 06:45:05PM +0000, João Almeida Santos wrote:
> bash-5.1$ cat << $PATH

That's not how a here-document is intended to be used.  A here-document
lets you drop a blob of text directly into your script and use that as
standard input for some command, without needing to store the text in a
separate file.

Here's an example of how it's often used:

usage() {
    cat << 'EOF'
usage: myprogram [-abcxyz] [-f inputfile]

Description of options:
  -a   all the things
  -b   make it bad
  ...
EOF
}


Using the contents of a variable as the sentinel to mark the end of
the here-document is not a good idea, and using $PATH specifically is
a VERY bad idea.

It kinds looks like you actually wanted a here-string, not a here-document,

IFS=: read -ra paths <<< "$PATH"

Was that what you were trying to do?  To use the content of PATH as your
input?  That's a here-string and uses the <<< operator, not <<.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]