I Get "Dquote>" as a Result of Executing a Program in Linux Shell

What is the quote command?

quote is a helper function in /usr/share/bash-completion/bash_completion:

# This function shell-quotes the argument
quote()
{
local quoted=${1//\'/\'\\\'\'}
printf "'%s'" "$quoted"
}

I would not use it since it's only available in interactive shells when completion is enabled.

If you want to escape special characters in a script you can use ${var@Q} or printf %q instead.

$ wendys="Where's the beef?"
$ echo "${wendys@Q}"
'Where'\''s the beef?'
$ printf '%q\n' "$wendys"
Where\'s\ the\ beef\?

How does cat EOF work in bash?

This is called heredoc format to provide a string into stdin. See https://en.wikipedia.org/wiki/Here_document#Unix_shells for more details.


From man bash:

Here Documents


This type of redirection instructs the shell to read input from
the current source until a line
containing only word (with no trailing
blanks) is seen.

All of the lines read up to that point are then used as the
standard input for a command.

The format of here-documents is:

          <<[-]word
here-document
delimiter

No parameter expansion, command substitution, arithmetic expansion, or
pathname expansion is performed on
word. If any characters in word are
quoted, the
delimiter is the result of quote removal on word, and the lines
in the here-document are not expanded.
If word is unquoted, all lines of the
here-document are subjected to parameter expansion, command
substitution, and arithmetic
expansion. In the latter case, the
character sequence \<newline> is
ignored, and \ must be used to quote the characters \, $, and `.

If the redirection operator is <<-, then all leading tab characters
are stripped from input lines and the
line containing delimiter. This
allows here-documents within shell scripts to be indented in a natural fashion.

Stuck in Terminal after echo

You need to leave the terminal with Ctrl + C or Ctrl + D. This is caused because you did not close the opened quote. You can also type a closing quote to exit the >.

Sample Image

The arrow > means, terminal is waiting for you to close the opened quote.

If you want to use a quote in your echo, you can escape it with backslash

echo Trump\'s Tower

You can read This for more info.

Actual meaning of 'shell=True' in subprocess

The benefit of not calling via the shell is that you are not invoking a 'mystery program.' On POSIX, the environment variable SHELL controls which binary is invoked as the "shell." On Windows, there is no bourne shell descendent, only cmd.exe.

So invoking the shell invokes a program of the user's choosing and is platform-dependent. Generally speaking, avoid invocations via the shell.

Invoking via the shell does allow you to expand environment variables and file globs according to the shell's usual mechanism. On POSIX systems, the shell expands file globs to a list of files. On Windows, a file glob (e.g., "*.*") is not expanded by the shell, anyway (but environment variables on a command line are expanded by cmd.exe).

If you think you want environment variable expansions and file globs, research the ILS attacks of 1992-ish on network services which performed subprogram invocations via the shell. Examples include the various sendmail backdoors involving ILS.

In summary, use shell=False.

How to execute bash variable with double quotes and get the output in realtime

In your array version, double quotes escaped by a backslash become part of the arguments, which is not intended.

So removing backslashes should fix the issue.



Related Topics



Leave a reply



Submit