Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
73 votes
1 answer
13k views

What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?

Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do ...
Michael Homer's user avatar
6 votes
3 answers
7k views

shell: Quote string with single quotes rather than backslashes

How can I quote a string with single quotes? Eg, I can do: $ printf "%q\n" 'two words' two\ words $ Is there a way to get a single- (or double-) quoted string as output, ie: $ MAGIC 'two words' '...
Tom Hale's user avatar
  • 31.3k
1 vote
1 answer
1k views

Invoking zmv from bash

I have recently discovered this technique for renaming files using zsh: autoload zmv zmv '(*).JPG' '$1.jpg' which I can also write as: autoload zmv; zmv '(*).JPG' '$1.jpg' This works as advertised ...
Manngo's user avatar
  • 233
7 votes
1 answer
3k views

Why does `zip` in a for loop work when the file exists, but not when it doesn't?

I have a directory that contains several sub-directories. There is a question about zipping the files that contains an answer that I ever-so-slightly modified for my needs. for i in */; do zip "zips/...
Wayne Werner's user avatar
  • 11.9k
3 votes
1 answer
115 views

zsh fail to keep unquoted `$*` and `$@` equal

All shells tested do the same for the (quoted) pair "$*" and "$@" with this code: c='set a b @ c; IFS=:,@ ; a=$(printf "<%s> " "$*"); b=$(printf "<%s> " "$@"); printf "%-20s and %-20s\n" "...
user avatar
8 votes
2 answers
3k views

Running commands stored in shell variables

The following works in my shell (zsh): > FOO='ls' > $FOO file1 file2 but the following doesn't: > FOO='emacs -nw' > $FOO zsh: command not found: emacs -nw even though invoking emacs -...
Amelio Vazquez-Reina's user avatar
13 votes
3 answers
30k views

Treatment of backslashes across shells

How do echo and printf treat backslashes in zsh, bash and other shells? Under zsh I get the following behavior: $ echo "foo\bar\baz" foaaz $ echo "foo\\bar\\baz" foaaz $ echo 'foo\...
Amelio Vazquez-Reina's user avatar
181 votes
1 answer
78k views

When is double-quoting necessary?

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
  • 15.7k
3 votes
4 answers
2k views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
Amelio Vazquez-Reina's user avatar
1 vote
2 answers
3k views

Weird zsh grep -P behaviour

I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is ...
Nakilon's user avatar
  • 144
17 votes
1 answer
22k views

Wrapping a command that includes single and double quotes for another command

I recently learned about watch, but am having trouble making it work with relatively sophisticated commands. For example, I would like to ask watch to run the following command on zsh every three ...
Amelio Vazquez-Reina's user avatar
29 votes
3 answers
30k views

Escaping quotes in zsh alias

Following on from this question about stripping newlines out of text, I want to turn this into a zsh alias as follows: alias striplines=' awk " /^$/ {print \"\n\"; } /./ {printf( \" %s \",$0);}"' I'...
Seamus's user avatar
  • 3,713