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
1381
votes
25 answers

How to escape single quotes within single quoted strings

Let's say, you have a Bash alias like: alias rxvt='urxvt' which works fine. However: alias rxvt='urxvt -fg '#111111' -bg '#111111'' won't work, and neither will: alias rxvt='urxvt -fg \'#111111\' -bg \'#111111\'' So how do you end up matching up…
cons
  • 14,423
  • 4
  • 20
  • 14
264
votes
21 answers

What Vim command(s) can be used to quote/unquote words?

How can I quickly quote/unquote words and change quoting (e.g. from ' to ") in Vim? I know about the surround.vim plugin, but I would like to use just Vim.
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
169
votes
17 answers

Build a JSON string with Bash variables

I need to read these bash variables into my JSON string and I am not familiar with bash. any help is appreciated.…
nad87563
  • 3,672
  • 7
  • 32
  • 54
152
votes
7 answers

I just assigned a variable, but echo $variable shows something else

Here are a series of cases where echo $var can show a different value than what was just assigned. This happens regardless of whether the assigned value was "double quoted", 'single quoted' or unquoted. How do I get the shell to set my variable…
that other guy
  • 116,971
  • 11
  • 170
  • 194
100
votes
6 answers

How to properly nest Bash backticks

Either I missed some backlash or backlashing does not seem to work with too much programmer-quote-looping. $ echo "hello1-`echo hello2-\`echo hello3-\`echo hello4\`\``" hello1-hello2-hello3-echo…
hhh
  • 50,788
  • 62
  • 179
  • 282
93
votes
12 answers

Using quotation marks inside quotation marks

When I want to do a print command in Python and I need to use quotation marks, I don't know how to do it without closing the string. For instance: print " "a word that needs quotation marks" " But when I try to do what I did above, I end up…
Thi G.
  • 1,578
  • 5
  • 16
  • 27
82
votes
4 answers

Sed gives: sed: can't read : No such file or directory

I have the following bash script which repeats for each image found. It needs to iterated over all html, css and js files, and replace all occurrences of an image within that file. for image in app/www/images-theme-dark/*.png do echo…
Bas van Dijk
  • 9,933
  • 10
  • 55
  • 91
62
votes
14 answers

Write CSV To File Without Enclosures In PHP

Is there a native function or solid class/library for writing an array as a line in a CSV file without enclosures? fputcsv will default to " if nothing is passed in for the enclosure param. Google is failing me (returning results for a whole bunch…
Derek Reynolds
  • 3,473
  • 3
  • 25
  • 34
49
votes
3 answers

Escape backquote in a double-quoted string in shell

For the command: /usr/bin/sh -c "ls 1`" (a backquote after 1). How to make it run successfully? Adding a backslash before "`" does not work. ` is a special char as we know, and I tried surrounding it with single quote too (/usr/bin/sh -c "ls…
user221839
48
votes
3 answers

Why does shell ignore quoting characters in arguments passed to it through variables?

These work as advertised: grep -ir 'hello world' . grep -ir hello\ world . These don't: argumentString1="-ir 'hello world'" argumentString2="-ir hello\\ world" grep $argumentString1 . grep $argumentString2 . Despite 'hello world' being enclosed by…
Ben Wilhelm
  • 1,898
  • 3
  • 15
  • 12
42
votes
5 answers

What is the meaning of “quasi” in quasiquotations?

Some languages like Haskell (or Nemerle) have quasiquotations. I wonder what the “quasi” means and if there also exist “quotations” without the “quasi” part.
soc
  • 27,983
  • 20
  • 111
  • 215
38
votes
1 answer

bash : cd : too many arguments

if i need to go to my directory named as"exception handling" then i write (cd exception handling) but it gives error too many arguments
Veerabala J
  • 553
  • 1
  • 5
  • 14
38
votes
5 answers

How to escape the single quote character in an ssh / remote Bash command

I'm building a small set of scripts for remotely starting, stopping and checking the status of a process. The stop of these scripts should look for a process and kill it. Therefore I do: ssh deploy@hera 'kill -9 `ps -ef | grep MapReduceNode | grep…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
37
votes
8 answers

Python module to shellquote/unshellquote?

Is there anything in the Python standard library that will properly parse/unparse strings for using in shell commands? I'm looking for the python analog to perl's String::ShellQuote::shell_quote: $ print String::ShellQuote::shell_quote("hello",…
YGA
  • 9,546
  • 15
  • 47
  • 50
35
votes
12 answers

Can awk deal with CSV file that contains comma inside a quoted field?

I am using awk to perform counting the sum of one column in the csv file. The data format is something like: id, name, value 1, foo, 17 2, bar, 76 3, "I am the, question", 99 I was using this awk script to count the sum: awk -F, '{sum+=$3} END…
maguschen
  • 765
  • 2
  • 8
  • 12
1
2 3
39 40