All Questions
11
questions
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 $...
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 ...
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 ...
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'...
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 ...
10
votes
4
answers
4k
views
Why does cut fail with bash and not zsh?
I create a file with tab-delimited fields.
echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input
I have the following script named zsh.sh
#!/usr/bin/env zsh
while read line; do
<<<$...
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 -...
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'
'...
3
votes
1
answer
2k
views
Escaping quotes for scp
I needed to write a that behaves correctly with nasty (spaces, braces, etc..)
filenames.
scp -rv "$1" shiny:/Volumes/Seagate3To/\"$1\"
This function works, but I don't understand why the quotes ...
3
votes
1
answer
973
views
On passing arguments to programs through array variables
NB: though the question below features rsync, it is not a question about rsync; it is a question about zsh arrays.
If I initialize the variable EXCLUDES like this
EXCLUDES=( --exclude=/foo --exclude=...
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 ...