` 和 ' 之间有什么区别?在编程方面,例如 MySQL 和 shell

发布于 2024-08-08 15:46:28 字数 80 浏览 2 评论 0原文

phpMySQL 使用反引号 ` 来包围列名,我刚刚看到人们在 shell 脚本中使用反引号。

如果他们使用 ' ,那是一样的吗?

phpMySQL use backticks ` to surround column names, and I've just see people use backticks in shell scripts.

Is that the same if they use ' ?

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

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

发布评论

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

评论(2

≈。彩虹 2024-08-15 15:46:28

在 MySQL 中,反引号可用于括起保留字的表名和列名,如下所示:

SELECT  *
FROM    `table`

单引号仅表示字符串常量:

SELECT  *
FROM    `table`
WHERE   `name` = 'test'

在 shell 中,反引号可让您将一个命令的输出用作另一个命令的参数:

echo `date`

将执行 date 并将其输出用作 echo 的参数。

单引号允许您在参数内使用空格、美元符号和反斜杠:

echo '$HOSTNAME'

将按原样输出字符串 $HOSTNAME

echo $HOSTNAME
echo "$HOSTNAME"

两者都会输出环境变量 HOSTNAME 的值。

In MySQL, backticks could be used to enclose table and column names which are reserved words, like this:

SELECT  *
FROM    `table`

Single quotes just denote a string constant:

SELECT  *
FROM    `table`
WHERE   `name` = 'test'

In shells, backticks let you use the output of one command as an argument to another command:

echo `date`

will execute date and use its output as an argument to echo.

Single quotes let you use whitespaces, dollar signs and backslashes inside the arguments:

echo '$HOSTNAME'

will output the string $HOSTNAME as it is,

echo $HOSTNAME
echo "$HOSTNAME"

both will output the value of the environment variable HOSTNAME.

无人问我粥可暖 2024-08-15 15:46:28

在 shell 中,一对反引号将被它们所包含的命令的 (stdout) 输出替换。

X=`expr 3 \* 2 + 4` # expr evaluate arithmatic expressions. man expr for details.
echo “$X”

In shell, a pair of backticks will be replaced by the (stdout) output of the command they enclose.

X=`expr 3 \* 2 + 4` # expr evaluate arithmatic expressions. man expr for details.
echo “$X”
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文