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

All Questions

Tagged with
1 vote
1 answer
181 views

Run `git commit -m` with single quotes in zsh

I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
Justin Breen's user avatar
7 votes
2 answers
1k views

Echoing "!" inside a string does some weird things [duplicate]

If I type in this: echo "Hello, World!" I don't know the name of it, but it prompts me for the next line. You know the PS2 thing. Or if you type echo \ and press Enter. Why? Well I know ...
Bog's user avatar
  • 1,034
1 vote
2 answers
342 views

Please explain the behavior of these parameter expansions using IFS?

I'm trying to figure out how to use the ${parameter%word} expansion with $@ and $*. It started by trying to make a script to combine pdfs using ghostscript, but I ran into some weird behavior with ...
mangoduck's user avatar
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
16 votes
3 answers
9k views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[@...
antonio's user avatar
  • 1,463
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 <<<$...
Sparhawk's user avatar
  • 20.1k
18 votes
1 answer
5k views

Why does this ffmpeg command work in bash and not zsh?

Today I got home from work (run bash on an Ubuntu box) and tried to run some code on my local arch box with my beloved zsh and the commands were failing? The command is below with the personal info ...
John Allard's user avatar
  • 1,378
4 votes
1 answer
1k views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
user1934428'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