Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the purpose of the grave accent ` in failure messages? #470

Closed
NorseGaud opened this issue Jul 25, 2021 · 11 comments · Fixed by #506
Closed

What's the purpose of the grave accent ` in failure messages? #470

NorseGaud opened this issue Jul 25, 2021 · 11 comments · Fixed by #506
Labels
Component: Bash Code Everything regarding the bash code Priority: Medium Wrong or misleading documentation, broken behavior with workaround Type: Question

Comments

@NorseGaud
Copy link
Contributor

Been there from day one: sstephenson/bats@c850527#diff-2285302ec7310b89fd9edfef3694598bebfa056fdbfd7e5d607026f64a68d734R80

It seems to work just fine when changing it to ' instead. I'd like to open this to discuss what potential downfalls there are of removing it.

@NorseGaud
Copy link
Contributor Author

NorseGaud commented Jul 25, 2021

It makes bash code blocks really ugly:
Screen Shot 2021-07-25 at 3 32 53 PM

@martin-schulze-vireso
Copy link
Member

I think this is a more or less historc typographic gimmick https://en.wikipedia.org/wiki/Quotation_mark#Typewriters_and_early_computers. With regard to your example it might be better to use ` also for closing the command, which should fix the parsing and maybe enable syntax highlighting.

@NorseGaud
Copy link
Contributor Author

NorseGaud commented Jul 26, 2021

@martin-schulze-vireso , so would you favor a PR for ending with ` or simply removing ` altogether?

@martin-schulze-vireso
Copy link
Member

It really depends on the context. Could you try what the fully `` wrapped version looks like in the environment you showed above?

@NorseGaud
Copy link
Contributor Author

NorseGaud commented Jul 27, 2021

❯ bin/bats --filter "^extended syntax" test/bats.bats
 ✓ extended syntax

1 test, 0 failures

❯ BATS_TRACE_LEVEL=1 bin/bats --filter "^extended syntax" test/bats.bats
 ✗ extended syntax
   (in test file test/bats.bats, line 329)
     `[ "${lines[7]}" = 'ok 2 a passing test' ]` failed
   + bats-exec-suite -x /Users/norsegaud/bats-core/test/fixtures/bats/failing_and_passing.bats

❯ BATS_TRACE_LEVEL=2 bin/bats --filter "^extended syntax" test/bats.bats
 ✗ extended syntax
   (in test file test/bats.bats, line 329)
     `[ "${lines[7]}" = 'ok 2 a passing test' ]` failed
   + bats-exec-suite -x /Users/norsegaud/bats-core/test/fixtures/bats/failing_and_passing.bats
   1..2
   suite /Users/norsegaud/bats-core/test/fixtures/bats/failing_and_passing.bats
   begin 1 a failing test
   not ok 1 a failing test
   # (in test file test/fixtures/bats/failing_and_passing.bats, line 2)
   #   `false' failed
   begin 2 a passing test
      
   ok 2 a passing test

1 test, 1 failure

Is this what you mean? So we'd instead potentially change it to end in ` too? I think that looks pretty good, if not better than ' ' wrapping.

@martin-schulze-vireso
Copy link
Member

No, I meant the environment from the screenshot above. I'd like to see if it fixes the highlighting.

@jasonkarns
Copy link
Member

I'd like to dig more into the rationale for it existing in the first place, before we change it. I've seen this pattern frequently enough in other heavily used shell scripts and tools that I don't believe it was accidental.

@NorseGaud
Copy link
Contributor Author

https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_03

Some implementations have allowed the end of the word to terminate the backquoted command substitution, such as in:
"`echo hello"

@NorseGaud NorseGaud changed the title [Dicusssion] What's the purpose of the ` in failure messages? [Dicusssion] What's the purpose of the grave accent ` in failure messages? Jul 27, 2021
@NorseGaud
Copy link
Contributor Author

NorseGaud commented Jul 27, 2021

https://unix.stackexchange.com/questions/121927/why-bash-encapsulates-syntax-error-both-with-grave-accent-and-with-an-apostrophe

In certain fonts, those quotation marks will appear as opposing pairs of curled single quotes. It's passé in today's Unicode world, but the code and practices that produced such quoting derive from a time before Unicode, or before its widespread availability.

https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

Summary: Please do not use the ASCII grave accent (0x60) as a left quotation mark together with the ASCII apostrophe (0x27) as the corresponding right quotation mark (as in `quote'). Your text will otherwise appear rather strange with most modern fonts (e.g., on Windows and Mac systems). Only old X Window System fonts and some old video terminals show ASCII 0x60/0x27 as left and right quotation marks, while most modern systems follow the ISO and Unicode standards instead. If you can use only ASCII’s typewriter characters, then use the apostrophe character (0x27) as both the left and right quotation mark (as in 'quote'). If you can use Unicode characters, nice directional quotation marks are available in the form of characters U+2018, U+2019, U+201C, and U+201D (as in ‘quote’ or “quote”).

if displayed with old X fonts, but it looked rather ugly like
`quotation'

If you are the author of some Unix software, then please check, whether you use the ASCII character 0x60 (`) as a left quotation mark as in `quote'. Change it such that you use instead the character 0x27 (') on both sides, as in 'quote'. If you work in an environment where the UTF-8 encoding is already used everywhere (e.g., Plan9 and most modern GNU/Linux installations), you could even decide to use proper directional quotation marks, as in ‘quote’ or “quote”.

This seems to be a remnant from the past.

NorseGaud pushed a commit to NorseGaud/bats-core that referenced this issue Jul 27, 2021
@NorseGaud NorseGaud mentioned this issue Jul 27, 2021
2 tasks
@martin-schulze-vireso
Copy link
Member

martin-schulze-vireso commented Jul 29, 2021

@jasonkarns

I'd like to dig more into the rationale for it existing in the first place, before we change it. I've seen this pattern frequently enough in other heavily used shell scripts and tools that I don't believe it was accidental.

I think this thread established well enough that it is a typographic hack for older, non utf systems. Maybe we can offer configuration variables that allow users to decide on the delimiters?

@martin-schulze-vireso martin-schulze-vireso added Component: Bash Code Everything regarding the bash code Priority: Medium Wrong or misleading documentation, broken behavior with workaround Type: Question labels Sep 11, 2021
@martin-schulze-vireso martin-schulze-vireso changed the title [Dicusssion] What's the purpose of the grave accent ` in failure messages? What's the purpose of the grave accent ` in failure messages? Sep 11, 2021
@shadowspawn
Copy link

For interest, Commander had a similar request to change the quotes used in error messages. After some research we accepted the change. My conclusion was it was a dated convention, and I referenced one of same links as #470 (comment)

tj/commander.js#915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Bash Code Everything regarding the bash code Priority: Medium Wrong or misleading documentation, broken behavior with workaround Type: Question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants