Skip to main content

Questions tagged [quoting]

Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.

812 votes
13 answers
1.8m views

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
Dan's user avatar
  • 9,642
519 votes
10 answers
230k views

How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory: tohru:~ $ ls -l total 8 -rw-r--r-- 1 me ...
Astra's user avatar
  • 5,293
432 votes
4 answers
827k views

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't need ...
detly's user avatar
  • 5,420
378 votes
6 answers
422k views

�� or an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
Gilles 'SO- stop being evil''s user avatar
283 votes
3 answers
58k views

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
Stéphane Chazelas's user avatar
266 votes
6 answers
501k views

I came across the following command: sudo chown `id -u` /somedir and I wonder: what is the meaning of the ` symbol. I noticed for instance that while the command above works well, the one below does ...
gws's user avatar
  • 2,771
250 votes
3 answers
62k views

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them intact....
Wyatt Ward's user avatar
  • 4,122
243 votes
7 answers
800k views

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> <dbname><![CDATA[name]]></...
Harry Muscle's user avatar
  • 2,707
223 votes
3 answers
111k views

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
xenoterracide's user avatar
221 votes
6 answers
207k views

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
cwd's user avatar
  • 47.2k
214 votes
3 answers
206k views

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. What is the correct way to quote my variables? And how should I do it if these are ...
CousinCocaine's user avatar
213 votes
6 answers
345k views

$ ls -l /tmp/test/my\ dir/ total 0 I was wondering why the following ways to run the above command fail or succeed? $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my': No such ...
Tim's user avatar
  • 107k
190 votes
7 answers
189k views

I'm trying to use the curl command to access a http url with a exclamation mark (!) in its path. e.g: curl -v "http://example.org/!287s87asdjh2/somepath/someresource" the console replies with bash: .....
netbrain's user avatar
  • 2,255
183 votes
1 answer
82k views

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
kjo's user avatar
  • 16.5k
163 votes
5 answers
495k views

I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to ...
m33lky's user avatar
  • 2,765

15 30 50 per page
1
2 3 4 5
73