程序员需要哪些报价?

发布于 2024-07-16 04:34:16 字数 371 浏览 1 评论 0 原文

我的键盘只有普通引号,没有智能引号。

我发现我在 CGI 开发 中需要普通的AWK 中的向后的/SED

当我应该使用智能引号、普通引号和后向引号时,有什么规则吗?

显然,我需要编辑键盘布局才能获得智能引号。

My keyboard only has normal quotes, not the smart ones.

I have observed that I need normal ones in CGI development and the backward ones in AWK/SED.

Is there a rule when I should use smart quotes, normal ones and backward ones?

Obviously, I need to edit my keyboard layout to get the smart quotes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

焚却相思 2024-07-23 04:34:16

如果您的意思是智能引号中的 ` ,那么这实际上称为“反引号”。 智能引号是指当您键入 ' 和 " 时,但会根据上下文自动获取 ' and ' 或“ and ”。我不确定如何在 awk 或 sed 中使用智能引号。

在 shell 中,反引号,例如 < code>`command`,用于计算命令并将其中命令的结果替换为正在计算的 shell 表达式;它可用于计算和传递给另一个命令,或设置变量。 更容易计算出许多引用规则。

为了减少歧义,您可以使用 $(command),这使得在 shell 中,'"< /code> 也不同。 " 用于需要变量替换和转义序列的字符串。' 表示仅包含引号内的字符的字符串,不包含变量插值或转义序列。

因此,例如:

$ name=world
$ echo "Hello, $name"
Hello, world
$ echo 'Hello, $name'
Hello, $name
$ echo "Testing \\ escapes"
Testing \ escapes
$ echo 'Testing \\ escapes'
Testing \\ escapes
$ echo `ls`
example-file another-example
$ echo 'ls'
ls
$ echo "ls"
ls

其他脚本语言,例如 Perl 和 Ruby,也有类似的规则,尽管可能存在细微的差异。

If you mean ` by smart quotes, then that is actually called "backquote". Smart quotes are when you type ' and ", but get ‘ and ’ or “ and ” automatically depending on the context. I'm not sure how you would use smart quotes in awk or sed.

In the shell, backquotes, such as `command`, are used to evaluate a command and substitute the result of the command within them into the shell expression being evaluated; it can be used to compute and argument to another command, or to set a variable. For less ambiguity, you can instead use $(command), which makes a lot of quoting rules easier to work out.

In the shell, ' and " are also different. " is used for strings in which you want variable substitution and escape sequences. ' represents a string containing just the characters within the quotes, with not variable interpolation or escape sequences.

So, for example:

$ name=world
$ echo "Hello, $name"
Hello, world
$ echo 'Hello, $name'
Hello, $name
$ echo "Testing \\ escapes"
Testing \ escapes
$ echo 'Testing \\ escapes'
Testing \\ escapes
$ echo `ls`
example-file another-example
$ echo 'ls'
ls
$ echo "ls"
ls

Other scripting languages, such as Perl and Ruby, have similar rules, though there may be slight differences.

童话里做英雄 2024-07-23 04:34:16

智能引号用于漂亮的排版。 它们与编程无关。

编辑:您确实需要的报价。

  • 双引号:" " 在许多语言中用于表示文字字符串
  • 单引号:' ' 在某些语言(如 C)中用于文字字符,在 javascript 和 php 等语言中用于字符串。 (例如,如果您需要打印字符串“foo”,则可以使用 '"foo"'
  • 反引号:在 UNIX shell 中,指示将一个命令的标准输出替换为一行定义另一个命令的文本。 例如 echo ``date\ 可能会执行 echo Sat Mar 1 09:43:00 GMT 2008 并打印 Sat Mar 1 09:43:00 GMT 2008。

Smart quotes are for beautiful typesetting. They have nothing to do with programming.

Edit: the quotes you do need.

  • Double quotes: " " they are used for literal strings in many languages
  • Single quotes: ' ' used for literal characters in some languages like C and for strings in languages like javascript and php. (For example if you need to print a string "foo", you could use '"foo"')
  • Back quotes: in UNIX shells, to indicate substitution of the standard output from one command into a line of text defining another command. For example echo ``date\ might execute echo Sat Mar 1 09:43:00 GMT 2008 and print Sat Mar 1 09:43:00 GMT 2008.
樱娆 2024-07-23 04:34:16

反引号在 shell、AWKPerl 编程,以及在 TeX。 除此之外,您可能不会经常使用它们。

Backticks are used a lot in shell, AWK, and Perl programming, and when doing documents in TeX. Other than that, you probably won't use them much.

小…楫夜泊 2024-07-23 04:34:16

聪明的引言是魔鬼。

Smart quotes are the devil.

撑一把青伞 2024-07-23 04:34:16

据我所知,没有语言需要(或者甚至不一定支持)“智能引号”,除非您将反引号字符 ` 称为智能引号。 如果是这种情况,许多语言都支持反引号。 例如, BashRuby 使用反引号进行命令替换。

要回答这个问题,当我应该使用智能引号和普通引号时是否有任何规则?,是的,有一个规则(再次假设您说“智能引号”时指的是反引号)。 在大多数语言中,不同类型的引用会带来不同类型的行为。 规则是,了解该特定语言的行为是什么,然后选择给出该行为的引用。

As far as I know, no language requires (or necessarily even supports) "smart quotes" unless you are calling the backtick character, `, a smart quote. If that's the case, many languages support the backtick. For example, both Bash and Ruby use the backtick for command substitution.

To answer the question Is there any rule when I should use smart quotes and normal ones?, yes, there is a rule (again, assuming you mean the backtick when you say "smart quotes"). In most languages, different types of quoting give you different types of behavior. The rule is, learn what the behavior is for that particular language, and then pick the quote that gives you that behavior.

我很OK 2024-07-23 04:34:16

智能引号是文字处理功能。 当您输入“quote”时,它会自动替换为“quote”或“quote”。 我认为你的命名法有误。

Smart quotes is word processor feature. When you type "quote" it gets automatically replaced with “quote” or „quote”. I think you got your nomenclature wrong.

画骨成沙 2024-07-23 04:34:16

仅供参考,“智能引号”的另一个术语(我以前从未听说过)是严重的口音。

我认为之前的答案中已经非常清楚地列出了规则。

Just an FYI, another term for 'smart quotes' (which I have never heard of that before), is grave accent.

I think the rules have been laid out pretty clearly in previous answers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文