Questions tagged [quoting]

The use of quotation marks (typically, `'` or `"`) to mark tokens as string literals or strings subject to interpolation, or to treat multiple whitespace-separated tokens as a single unit.

Use this tag for questions about the correct use of quotation marks in programming, with respect to:

  • how to use quotation marks to mark text as a literal not to be interpreted in any way.
  • how to use quotation marks to mark text as subject to string interpolation.
  • how to escape (encode) quotation marks inside text already enclosed in quotation marks.

Especially in shell programming, with respect to:

  • when what quotation marks are needed, and if quoting is needed at all, including quoting of individual characters with \.
  • how to use quoting to partition a list of tokens into distinct arguments that may have embedded whitespace.
  • when quotation marks are considered part of the input vs. recognized syntactically by the shell (quote removal).
589 questions
10
votes
4 answers

Perl one-liner with single quote

I use a Perl one-liner to create an SQL statement, but I am not able to include single quotes. This is what I want: Take the first field and add quotes to it. echo "a,b" | perl -F',' -lane 'print $F[0];' 'a' I tried a few different ways, but it…
sfgroups
  • 18,151
  • 28
  • 132
  • 204
9
votes
1 answer

How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping?

This self-answered question aims to give a systematic overview of the PowerShell CLI (command-line interface), both for Windows PowerShell (powershell.exe) and PowerShell (Core) v6+ (pwsh.exe on Windows, pwsh on Unix). While official help topics…
9
votes
2 answers

Escaping quotes when using SSH

I'm trying to build a simple deployment script for my PHP apps. I know there are several tools for this job (Capistrano, Phing, etc.) but they seem like a lot of work for my simple deployment routine. I use sshpass to avoid typing my password over…
fedeisas
  • 1,991
  • 2
  • 22
  • 34
9
votes
5 answers

How to call popen() with a pathname containing spaces under Windows in C/C++?

I'm trying to call popen() using mingw like this: #define RUN_COMMAND "\"C:\\Program Files\\CA\\BrightStor ARCserve Backup\\ca_qmgr.exe\" \"-list\"" int main() { outputPointer = popen(RUN_COMMAND, "r"); ... } But I can't get it working. I…
GabrieleV
  • 2,303
  • 2
  • 16
  • 9
8
votes
2 answers

Run piped commands with eval

I have the following command line to check free space of a file system: fs_used=`df -h /u01 | sed '1d' | sed '1d' | awk '{print $4}' | cut -d'%' -f1` It works fine. It returns the percentage of the used space on the file system (without the %…
Ould Abba
  • 813
  • 1
  • 12
  • 25
8
votes
4 answers

bash script - unable to set variable with double quotes in value

Need help in fixing this bash script to set a variable with a value including double quotes. Somehow I am defining this incorrectly as my values foo and bar are not enclosed in double quotes as needed. My script thus far: #!/usr/local/bin/bash set…
noober
  • 1,427
  • 3
  • 23
  • 36
8
votes
1 answer

How to quote nested sub-shell arguments correctly?

How to pass a string with spaces to a command which returns itself a string with spaces? I tried the following four versions. arg='one arg' arg() { echo "arg: $1"; } printf '1 |%s|\n' $(arg "$arg") printf '2 |%s|\n' "$(arg $arg)" printf '3 |%s|\n'…
ceving
  • 21,900
  • 13
  • 104
  • 178
8
votes
2 answers

Pandas Read_CSV quotes issue

I have a file that looks like: 'colA'|'colB' 'word"A'|'A' 'word'B'|'B' I want to use pd.read_csv('input.csv',sep='|', quotechar="'") but I get the following output: colA colB word"A A wordB' B The last row is not correct, it should be…
A. Jameel
  • 81
  • 1
  • 1
  • 2
8
votes
1 answer

Passing arguments which include double quotes to subprocess using Python

I'm looking for a way to pass an argument which contains double quotes to python's subprocess module, without the double quotes being escaped. I've seen this question asked a few different times when the quotes are surrounding the arg, but the…
BetterOffEd
  • 81
  • 1
  • 1
  • 4
7
votes
1 answer

Put $$ in dollar-quoted string in PostgreSQL

I have a function in Postgres: CREATE OR REPLACE FUNCTION upsert(sql_insert text, sql_update text) RETURNS integer AS $BODY$ BEGIN EXECUTE sql_insert; RETURN 1; EXCEPTION WHEN unique_violation THEN EXECUTE sql_update; RETURN…
ilyasfals
  • 99
  • 2
  • 8
7
votes
1 answer

Parsing of HTTP Headers Values: Quoting, RFC 5987, MIME, etc

What confuses me is decoding of HTTP header values. Example Header: Some-Header: "quoted string?"; *utf-8'en'Weirdness Can header value's be quoted? What about the encoding of a " itself? is ' a valid quote character? What's the significance of a…
unixman83
  • 9,421
  • 10
  • 68
  • 102
7
votes
2 answers

Brace Delimiters with qq Don't Interpolate Code in Raku

Sorry if this is documented somewhere, but I haven't been able to find it. When using brace delimiters with qq, code is not interpolated: qq.raku #!/usr/bin/env raku say qq{"Two plus two": { 2 + 2 }}; say qq["Two plus two": { 2 + 2 }]; $ ./qq.raku…
JustThisGuy
  • 1,109
  • 5
  • 10
7
votes
1 answer

Translating single quote using trans

I can't find a way to translate using trans a single quote to a escaped single quote: say ($ = "'well done'").=trans("'" => "\\\'" ) ;# OUTPUT: «\well done\␤» say ($ = "'well done'").=trans(<'> => Q [\'] ) ;# OUTPUT: «\well done\␤» say ($ = "'well…
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
7
votes
2 answers

Quote only the required columns using pandas to_csv

I need to generate a csv using pandas to_csv function. I tried quote=csv.QUOTE_NONNUMERIC. But for one of the date time column I dont need double quotes. Is there a way to select the columns for which we want double quotes?
Sowmika
  • 171
  • 3
  • 11
7
votes
4 answers

Do I need to quote command substitutions?

According to the Google Shell Style Guide, I should: Always quote strings containing variables, command substitutions, spaces or shell meta characters, unless careful unquoted expansion is required. Maybe I am misinterpreting what they mean by…
Joshua Spence
  • 732
  • 1
  • 6
  • 19