1

Command 1:

$ rm hello.txt 2>/dev/null || { echo “Couldn’t delete hello.txt” }
"Couldn't delete hello.txt"

Command 2

$ rm hello.txt 2>/dev/null || { echo 'Couldn’t delete hello.txt' }
Couldn't delete hello.txt

Note: hello.txt doesn't exist in the current directory.

3
  • 8
    I assume for bash and are not quotes.
    – Cyrus
    Nov 26, 2016 at 7:28
  • the rm part is completely irrelevant here. It's all about the echo part
    – phuclv
    May 7, 2017 at 0:30
  • 1
    Neither command would do as you say. Any command in { ...; } must always end in semi-colon or a newline character.
    – Kusalananda
    Jun 4, 2022 at 6:14

2 Answers 2

16

The first command

rm hello.txt 2>/dev/null || { echo “Couldn’t delete hello.txt” }

contains the characters <U+201C>(LEFT DOUBLE QUOTATION MARK), <U+2019> (RIGHT SINGLE QUOTATION MARK) and <U+201D> (RIGHT DOUBLE QUOTATION MARK) which are in no way special to the shell and are output as such.

The second command

rm hello.txt 2>/dev/null || { echo 'Couldn’t delete hello.txt' }

contains a string enclosed in single quotes; the character between n and t is again <U+2019>, which is not special to the shell.

1

The pair “” is called smart quotes. Similarly, your in Couldn’t is also a smart quote.

Those are unlike normal quotes in the sense that they're curly to differentiate the begin and end of the quoting part. They have no meaning in most (if not all) programming/scripting languages I know and are just the same as other Unicode characters.

So your first echo doesn't actually have any quote and the command will receive those words as separate arguments. You can check that easily

$ for s in “Couldn’t delete hello.txt”; do echo $s; done
“Couldn’t
delete
hello.txt”

$ for s in 'Couldn’t delete hello.txt'; do echo $s; done
Couldn’t delete hello.txt

In fact your output is wrong (did you really copy paste it?) because there's no way smart quotes become normal quotes after echo. The output should still be smart quote as in my example above

As you can see, the second case is a single string containing a Unicode character outside the ASCII range, so the quotes will be stripped by the shell

See What are curly quotes and can I use them in my code?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .